Home >Backend Development >PHP Tutorial >帮看下这段代码,插入数据库部分出问题,没找到错误

帮看下这段代码,插入数据库部分出问题,没找到错误

WBOY
WBOYOriginal
2016-06-23 13:58:56962browse

<!DOCTYPE html><html>        <head>                <meta charset=utf-8/>                <title>War-game -Add Your score</title>        </head>        <body>                <h2>War game - add your score</h2>                <?php                        if(!empty($_POST['submit']))                        {                                $first_name=$_POST['first_name'];                                $last_name=$_POST['last_name'];                                $score=$_POST['score'];                                echo $first_name;                                echo $last_name;                                echo $score;                                $dbc=mysqli_connect('localhost','root','pengyu2408','score_list')or die('error in connet');                                $query="INSERT INTO score_lis(first_name,last_name,score) VALUES('$first_name','$last_name','$score')";                                mysqli_query($dbc,$query)or die('error_2');                                echo '<p>Thanks for adding your new high score!</p>';                                echo '<p><strong>FIRST_NAME:</strong>'.$first_name.'<br/>';                                echo '<strong>LAST_NAME:</strong>'.$last_name.'</p>';                                echo '<p><strong>Score:</strong>'.$score.'<br/></p>';                                echo '<p><a href="index.php"><<Back to hight score</a></p>';                                //clear the score data to clear the form                                $firet_name="";                                $last_name="";                                mysqli_close($dbc);                        }                ?>                <hr />                <form method ="post" action="<?php echo $_SERVER['PHP_SELF'];?>">                        <label for="name">FIRST NAME:</label>                        <input type="text" id="first_name" name="first_name" /><br />                        <label for="name">LAST NAME:</label>                        <input type="text" id="last_name" name="last_name"/><br />                        <label for="score">Score:</label>                        <input type="text" id="score" name="score"/><br />                        <hr />                        <input type="submit" value="ADD" name="submit"/>                </form>        </body></html

表是这样的


回复讨论(解决方案)

这上面在向mysql传入数据部分出了错误,但是我没找到,麻烦大家帮看看谢谢

出错的时候提示什么错误?


$query="INSERT INTO score_lis (first_name,last_name,score) VALUES ('$first_name','$last_name','$score')";空格

Call to undefined function mysqli_connect() in /var/www/addscore.php on line 25

检查php.ini中的extension=php_mysql.dl有没有去掉注释(;为注释符)如果有就去掉,重启Apache

Call to undefined function mysqli_connect() in /var/www/addscore.php on line 25
谢谢啦,找了半天,光找语法,忘记了自己今天刚重配置完服务器,搞定了 非常感谢

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn