Jag har problem med "mysqli_num_rows".
Det här är felmeddelandet:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\censur\processform.php on line 60
Jag har sökt på det. Men hittar inget svar som hjälper. Folk skriver bara precis vad som står i felmeddelandet. Att mysqli_num_rows kräver ett mysqli_result. Det hjälper inte så mycket...
Jag har läst och lärt från boken "PHP & MySQL for Dummies" och försökt få koden att fungera till mitt projekt.
Det är koden näst längst ner som jag har problem med. Den är ju inte helt färdig. Men det är ju för att den inte fungerar. jag vill ta reda på antalet rader i databasen så jag sen kan söka igenom databasen efter censurnamnet och se om det redan finns.
Det här är koden:
<?php
/* The information needed to connect to the databse */
$host = "127.0.0.1";
$user = "root";
$password = "";
$database = "censur";
$cxn = mysqli_connect($host,$user,$password,$database);
/* Gets todays date.
Difference between upper and lowercase */
$date = date("Y-m-d");
/* This part gets the filename without the file extension and file extension of the file.
Lets say we have a file called abc.censur. The code splits the name into two parts.
file_basename that is abc and
file_ext that is .censur */
$filename = $_FILES[Path][name];
##$file_basename = substr($filename, 0, strripos($filename, '.'));##
$file_ext = substr($filename, strripos($filename, '.'));
/* If the filename is empty, the censur won't be uploaded */
if($_POST[Name] == "")
{
echo "Du har glömt att ange ett namn!\n";
}
/* If a file haven't been chosen, the censur won't be uploaded */
elseif($_FILES[Path][name] == "")
{
echo "Du har glömt att lägga till en fil!\n";
}
/* If not the file extension is .censur, the censur won't be uploaded */
elseif($file_ext != ".censur")
{
echo "Du kan endast ladda upp censurfiler!\n";
}
/* If the filesize is bigger than 1mb, the censur won't be uploaded */
elseif($_POST[MAX_FILE_SIZE] > 1000000)
{
echo "Filen är för stor!\n";
}
/* If everything is fine, the censur will be uploaded */
else
{
echo "<p>censur filen har laddats upp</p>";
/* The connection is established */
/* This checks if the censurname allready excists */
$query = "SELECT COUNT(*) FROM censur";
$result = mysqli_query($cxn,$query);
$nrows = mysqli_num_rows($result);
/*
$query = "INSERT INTO censur (cenType,cenName,cenDate) VALUES ($_POST[Type],$_POST[Name],$date)";
mysqli_query($cxn,$query);
*/
}
?>
off-topic:
Som ni ser så har jag censurerat en del. Jag ville inte riskera att bryta mot en viss regel. Jag skulle troligtvis få en varning om jag har det ordet i koden...