<?php
$name= $_POST['name'];
$roll= $_POST['roll'];
$con= mysql_connect("localhost", "root","");
mysql_select_db("students");
$query = "update classmate SET name= '$name' where roll= $roll";
echo $query;
$run = $con -> query($query);
if($run){
echo "data Has been Updated";
}
else {
echo "Data Has not Updated";
}
?>
错误是:
致命错误:在$ run = $ con - &gt;中的非对象上调用成员函数query()查询($查询);
答案 0 :(得分:0)
要捕获连接错误,您可以使用try-catch块:
try {
$con= mysql_connect("localhost", "root","");
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
答案 1 :(得分:0)
您可以使用此代码:
$name= $_POST['name'];
$roll= $_POST['roll'];
$con= mysqli_connect("localhost", "root","","students");
$query = "update classmate SET name= '$name' where roll= $roll";
echo $query;
$run = mysqli_query($con, $query);
if($run){
echo "data Has been Updated";
} else {
echo "Data Has not Updated";
}