메신저 PHP에 익숙하지 않아 데이터베이스를 코딩하려고합니다. 전체 코드는 잘 작동하지만이 부울 오류가 발생합니다. 나는 $ 결과가 부울을 기다리고 있다고 생각한다. 우스운 일은 비디오를 정확히 따라 가면서 오류가 발생했습니다. 바라건대 누군가가 그 오류가 무엇을 의미하는지 그리고 어떻게 해결할 수 있는지 설명해 줄 수 있기를 바랍니다.Mysql이 작동하지만 부울을 기대합니다
오류 : 성공!
경고 : \ XAMPP \ htdocs를 \ introducingphp \ DataBaseTut3.php 라인 66
에경고 : mysqli_fetch_assoc()는 부울 C에 주어진 파라미터 1 mysqli_result되기를 기대 mysqli_free_result()가 파라미터 1 mysqli_result 될 것으로 예상 부울 C에 주어진 : \ XAMPP \ htdocs를 \ introducingphp \ DataBaseTut3.php 라인에 77
내 코드 :
<?php
//1.Create database connection
$dbhost = "localhost";
$dbuser = "weekeong";
$dbpass = "alexsage";
$dbname = "fyp";
$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
//Test if connection occurred.
if(mysqli_connect_errno()) {
die("Database connection failed: ".
mysqli_connect_error() .
" (" . mysqli_connect_errno(). ")"
);
}
?>
<?php
//2. Perform database query
// these are often form values in $_POST
$id = 5;
$name = "John xan";
$age = 30;
$birthdate = "19/03/1994";
$medical_allergies = "";
$phone = 88888888;
$address = "lame street";
$doctor_assigned = "Dr Lee";
$query = "INSERT INTO patients (";
$query .= " id, name, age, birthdate, medical_allergies, phone, address, doctor_assigned";
$query .= ") VALUES (";
$query .= " {$id}, '{$name}', {$age}, '{$birthdate}', '{$medical_allergies}', {$phone}, '{$address}', '{$doctor_assigned}'";
$query .= ")";
//query is not only to get something but to get sqli to do something for us so we still use query
$result = mysqli_query($connection, $query);
//Test for query error
if ($result) {
echo "SUCCESS!";
//success
//redirect_to ("somepage.php");
} else {
//Failure
//$message = "Creation failed";
die("Database query failed." .mysqli_error($connection));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Database 3</title>
</head>
<body>
<ul>
<?php
//3 Use returned data (if any)
while($doc = mysqli_fetch_assoc($result)) { // only creates row if there are results
// cannot use for each with fetch_row as it is not a PHP array, it is a result set from MY SQL. For Each will try to increment pointer at the end but MYSQL doesnt have array pointer so use while.
//output data from each row
?>
<li><?php echo $doc["name"]; ?></li>
<?php
}
?>
</ul>
<?php
//4. Release returned data
mysqli_free_result($result);
?>
</body>
</html>
<?php
//5. Close database connection
mysqli_close($connection);
?>
삽입 쿼리를 반복하려고합니까? 나는 당신이 필요 * SELECT * 거기에 –