Fatal error: Call to undefined function mysqli_num_row()

Status
Not open for further replies.

selina

In Runtime
Messages
228
hi,
i'm pretty new to the PHP...

I have a form which takes user's name and then, run a query to see if their names exist in the database. but i keep getting the following error when i try to run it:

Fatal error: Call to undefined function mysqli_num_row() in /var/www/wedding/rsvp.php on line 13

the web server is running on UNIX. I dont' know what more information is needed....

the code is:

<?php

$mysqli = mysqli_connect("localhost", "user", "password", "database");



/* check connection */

if (!$mysqli) {

die ('could not connect: ' . mysql_error());

}

else {

printf("name to find is " .$_POST["name"]."<br />");

$namesearch_sql="SELECT * FROM tbl_guests WHERE guest_name = '".$_POST['name']."'";

$namesearch_res=mysqli_query($mysqli, $namesearch_sql) or die(mysqli_error($mysqli));



if (mysqli_num_row($namesearch_res) < 1) {

printf("no name");

}

else {

while ($new = mysqli_fetch_array($namesearch_res)) {

$newname=$new['guest_name'];

printf("name: ".$newname);

}

}



/* close connection */

mysqli_close($mysqli);

}

?>
 
what is mysqli ? The error your getting means that the parser cannot find the function you're calling. The only way I know how to connect to mysql through php is the mysql_connect() method.
 
thanks for your reply.
mysqli is available for PHP 5. i figured out what the problems was for the posted codes. it was as simple as changing mysqli_num_row() to mysqli_num_rowS()...

anyways, i have another problem for PHP4, maybe you can help me.
i'm getting the error message:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in //path/rsvp.php on line 9

for the code:
<?php
$mysql = mysql_connect("localhost", "userid", "pw", "databse");
/* check connection */
if (!$mysql) {
die ('could not connect: ' . mysql_error());
}
else {
$display_block="name to find is \"" .$_POST["name"]."\"<br />";
$namesearch_sql="SELECT * FROM tbl_guests WHERE guest_name LIKE '".$_POST['name']."%'";
$namesearch_res=mysql_query($mysql, $namesearch_sql) or die(mysql_error($mysql));
if (mysql_num_rows($namesearch_res) < 1) {
$display_block .= "no name";
}
else {
$display_block="name found.";
}
/* close connection */
mysql_close($mysql);
}
?>

<html>
<head>
<title>RSVP</title>
</head>
<body>
<h2> RSVP </h2>
<?php echo "$display_block"; ?>
</body>
</html>
 
You answered your own question , you cannot use mysqli in version 4 , thats the way i understood it. Therefor it is not a valid resource ;)
 
but it seems like i'm getting the error for this code:
$namesearch_res=mysql_query($mysql, $namesearch_sql) or die(mysql_error($mysql));

in PHP5, it works fine (i need to replace "mysql" with "mysqli" tho)... does PHP4 works differently to run a query?
 
Status
Not open for further replies.
Back
Top Bottom