我正在尝试创建一个PHP表单,可以在其中向数据库中的表添加值,这是我的代码:
<?php
$host ="localhost";
$db_nome = "my_farneseluca";
$username = "farneseluca";
// Create connection
mysql_connect($host, $username) or die('Impossibile connettersi al server: ' . mysql_error());
mysql_select_db($db_nome) or die ('Accesso al database non riuscito: ' . mysql_error());
$table = $_POST['table'];
$descr = $_POST['descr'];
$certif = $_POST['certif'];
$sql = "INSERT INTO $table (DESCRIZIONE, CERTIFICAZIONE) VALUES ('$descr', '$certif');";
if ($con->query($sql) === TRUE)
{
echo 'users entry saved successfully';
}
else
{
echo 'Error: '. $con->error;
}
mysqli_close($con);
?>
<form method="post" action="editdata.php" target="">
Inserire tabella da modificare<br>
<input type="text" name="table"><br>
DESCRIZIONE<br>
<input type="text" name="descr"><br>
CERTIFICAZIONE<br>
<input type="text" name="certif"><br>
<input type="submit" value="Aggiorna">
</form>
当我单击“ Aggiorna”按钮时,页面显示此错误:
致命错误:在第96行的/membri/farneseluca/editdata.php中调用null的成员函数query()
我试图在其他帖子或google中查看,但我可以理解问题所在
答案 0 :(得分:1)
您尝试在$ con上调用query(),但是您尚未在任何地方声明$ con。
Fatal error: Call to a member function query() on null
定义$ con:
$con = mysqli_connect($host, $username) or die('Impossibile connettersi al server: ' . mysqli_error());