我有一個名爲'input1'的輸入框,名爲register.php。我想要做的是從input1中獲取值並將其存儲到數據庫中。當用戶點擊register.php的提交按鈕時,他將被重定向到另一個名爲demo.php的表單,該表單應將輸入框input1中輸入的值存儲到數據庫中。警告:mysqli_query()期望參數1爲mysqli,字符串與數據庫一起給出
出於某種原因
我得到以下錯誤:警告:mysqli_query()預計參數1是在C中給出的mysqli,字符串:\ XAMPP \ htdocs中\ MYAPP \ demo.php上演示線21。 PHP的;
demo.php:
<?php
//Step1
$db = mysql_connect('localhost','root','','forms1')
or die('Error connecting to MySQL server.');
$db_selected = mysql_select_db('forms1' , $db);
if(! $db_selected) {
die('db not selected'. mysql_error());
}
echo "connected";
$value =$_POST['input1'];
$sql =" INSERT INTO demo (input1) VALUES ('$value') ";
mysqli_query($sql , $db);
?>
register.php:
<form action ="demo.php" method ="post" />
<p> Input 1:<input type ="text" name ="input1" /> </p>
<input type ="submit" value ="submit">
</form>
你只混了'MySQL的&mysqli'.use'mysqli'而不是'mysql'.'mysql'已從最新版本的PHP中棄用。 –