这个问题在这里已经有答案了:
我可以在php中混合mysql api吗(4个答案)
两年前关门了。
我有一个用户表,正在尝试运行一个查询,以获取添加到表中的最后一个用户标识。我出错了。代码如下:
$connect = mysqli_connect("localhost","adhude","windows","photodb");
// Check connection
if(!$connect){
die("connection failed :"+ mysqli_connect_errno());
}else{
function NewUser(){
$sql = "INSERT INTO user (User_Name, Password) VALUES ('".$_POST["Email"]."','".$_POST["psw"]."')";
$result=mysqli_query($GLOBALS['connect'],$sql);
if($result){
echo "<script> alert('Records added successfully')</script>";
GetUserId();
}else {
echo "<script> alert('Records not added ')</script>";
}
}
//function to get the last added user id
function GetUserId(){
$sql="SELECT * FROM user ORDER BY User_Id DESC LIMIT 1";
$result=mysqli_query($GLOBALS['connect'],$sql);
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$arrayResult = mysql_fetch_array($result);
$Latest_User=$arrayResult['User_Id'];
}
我得到以下错误
致命错误:未捕获错误:调用c:\xampp\htdocs\web2\php\signup\u进程中未定义的函数mysql\u fetch\u array()。php:165 stack 跟踪:#0 c:\xampp\htdocs\web2\php\signup\u process.php(148):getuserid()#1 c:\xampp\htdocs\web2\php\signup\u process.php(203):newuser()#2 c:\xampp\htdocs\web2\php\signup\u process.php(214):signup()#3c:\xampp\htdocs\web2\pages\signup.php(14):include('c:\xampp\htdocs…')#4{main}在第165行的c:\xampp\htdocs\web2\php\signup\u process.php中抛出
165具有以下代码: $arrayResult = mysql_fetch_array($result);
1条答案
按热度按时间bvjveswy1#
你正在使用msqli所以
mysql_fetch_array
应该是mysqli_fetch_array
. 你也可以select MAX(User_ID) from users;
.此外,还应该使用prepared语句来避免sql注入。