Php Mysqli未定义变量
嗨,我正在用php和mysqli语句处理简单的crud项目 首先,一切正常,但例如Php Mysqli未定义变量,php,html,mysql,mysqli,Php,Html,Mysql,Mysqli,嗨,我正在用php和mysqli语句处理简单的crud项目 首先,一切正常,但例如mysqli\u num\u rows($result)返回多行,这会导致所有错误 这是我的PHP代码 <?php if(isset($_GET["email"]) && !empty(trim($_GET["email"]))){ // Include config file require_once 'db.php'; // Prepare a select statement $sq
mysqli\u num\u rows($result)
返回多行,这会导致所有错误
这是我的PHP代码
<?php
if(isset($_GET["email"]) && !empty(trim($_GET["email"]))){
// Include config file
require_once 'db.php';
// Prepare a select statement
$sql = "SELECT * FROM interns WHERE email = ?";
if($stmt = mysqli_prepare($con, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_id);
// Set parameters
$param_id = trim($_GET["email"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) == 1){
/* Fetch result row as an associative array. Since the result set
contains only one row, we don't need to use while loop */
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
// Retrieve individual field value
$firstname = $row["firstname"];
$lastname = $row["lastname"];
$cin = $row["cin"];
$phone_number = $row["phone_number"];
$address = $row["address"];
$school = $row["school"];
$intern_duration = $row["intern_duration"];
$departement = $row["departement"];
$cv = $row["cv"];
$internship_report = $row["internship_report"];
} else{
// URL doesn't contain valid id parameter. Redirect to error page
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
} else{
// URL doesn't contain id parameter. Redirect to error page
header("location: error.php");
exit();
}
?>
mysqli_stmt_bind_param($stmt,“i”,$param_id)
应该是字符串的s
,用于电子邮件地址。i
代表“整数”
您的查询可能返回多行,因为(可能)有多行包含整数
您还可以在查询中添加一个限制1
,这可能会有所帮助。“未定义变量”是哪一个?我无法计算whimits$行上有多少行,因为mysqli_num_rows($result)==1无效。它返回2行,但应该只返回1更改mysqli_num_rows($result)==1
到mysqli_num_rows($result)>0
那应该是一个s
。如果我照你说的做,我会尝试激活一行。我总是返回第一行是的,因为我先使用“id”,然后将其更改为“email”。感谢you@MarouaneSihad啊!!不客气。安全地享受日食;-)干杯