Hallo Ich arbeite an einfachen Crud-Projekt mit PHP und MySQL-Anweisung.Mysqli undefine Variable
Zuerst lief alles gut, aber zum Beispiel mysqli_num_rows($result)
gibt mehr als eine Zeile zurück, die alle Fehler verursacht.
das ist mein PHP-Code
<?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();
}
?>
Ich weiß, es ist vielleicht eine sehr einfache Fehler, aber es mich verrückt xD
* "undefinierbare Variable" * welche welche? Ich kann nicht zählen, wie viele Sie auf eine Laune haben –
seine $ -Zeile, weil mysqli_num_rows ($ result) == 1 ist nicht gültig, es gibt 2 Zeilen zurück, sollte aber nur 1 –
ändern 'mysqli_num_rows ($ result) == 1' zu 'mysqli_num_rows ($ result)> 0' –