当我尝试更新数据库中的表时,使用此代码我收到mysqli_error()正好需要1个参数,错误地给出了0。
我不确定自己哪里出错了,因为我已经查看过这些字段以确认其长度。
<?php
// Establish a connection to the database
$con = mysqli_connect("localhost", "root", "password");
// Check if there were any issues connecting to the database
if ( mysqli_connect_errno() != 0)
{
die("An error occurred trying to establish a connection: " .mysqli_connect_error());
}
// Select the database to work with.
$db = mysqli_select_db ($con, "SalesDB");
// Specify the query to run
$sqlString = "UPDATE Customer SET Cust_Fname ='".$_POST["FirstName"] ."', Cust_Lname='" .$_POST["LastName"] ."', Cust_Pasword='" .$_POST["Password"] ."', Cust_email='" .$_POST["Email"] ."', Cust_address='" .$_POST["Address"] ."', Cust_city='" .$_POST["City"] ."', Cust_state='" .$_POST["State"] ."', Cust_zip='" .$_POST["Zip"] ."', Locked_flag='" .$_POST["Lflag"]."', Emp_ID='" .$_POST["EmpID"]."' WHERE Cust_ID = '".$_POST["ID"] ."'";
// Run the query using the connection established earlier and assign the results to a results object.
$rs = mysqli_query ($con, $sqlString);
// Check if update was successful by checking whether the result returned is True
if ( !$rs)
{
$result = "There Was an Error Updating the Record".mysqli_error();
}
else
{
$result = "Record Updated Successfully";
}
// Close the connection
mysqli_close($con);
?>
答案 0 :(得分:0)
您必须发送连接到mysqli_error
试试这个
if ( !$rs)
{
$result = "There Was an Error Updating the Record".mysqli_error($con);
}
else
{
$result = "Record Updated Successfully";
}
答案 1 :(得分:-1)
阅读您的错误代码。
在
// Check if update was successful by checking whether the result returned is True
if ( !$rs)
{
$result = "There Was an Error Updating the Record".mysqli_error();
}
else
{
$result = "Record Updated Successfully";
}
mysqli_error()
期望连接的参数。传递给$con