尝试将数据发布到数据库时,会显示错误消息,指出未选择数据库。但是数据库中的内容显示在表格和选择菜单上。
<?php
$con = mysqli_connect("localhost", "root", "","radian");
if(!$con)
{
exit("Couldn't connect: ".mysqli_connect_error());
}
mysqli_set_charset($con, "utf8");
$insert_data = "UPDATE enquiries
SET ResponseDate = '".$current_date."',
Response = '".$txtResponse."',
Enquiry_No = '".$_SESSION['ses_staff']
."' WHERE Enquiry_No = '".$txtStudentId."'";
$execute = mysql_query($insert_data) or die(mysql_error());
$output= '<h4 style="margin-left:1em;width:15em;color:red;"> Response successful!. </h4>';
}else{
$output= '<h4 style="margin-left:1em;width:15em;color:red;"> </h4>';
}
答案 0 :(得分:1)
您的最终代码应与:
相同<?php
$con = mysqli_connect("localhost", "root", "", "radian");
if (!$con) {
exit("Couldn't connect: " . mysqli_connect_error());
}
mysqli_set_charset($con, "utf8");
$insert_data = "UPDATE enquiries SET ResponseDate = '" . $current_date . "', Response = '" . $txtResponse . "',Enquiry_No = '" . $_SESSION['ses_staff'] . "' WHERE Enquiry_No = '" . $txtStudentId . "'";
$execute = mysqli_query($con, $insert_data) or die(mysqli_error($con));
$output = '<h4 style="margin-left:1em;
width:15em;
color:red;"> Response successful!. </h4>';
所做的更改:
mysql_*
的所有实例,并使用正确的mysqli_*
函数替换。} else {
。注意:不推荐使用正式
mysql_*
个函数。所以没有必要使用它们。使用mysqli_*
或PDO。