Jump to content

[SOLVED] mysql_num_rows issues


Foser

Recommended Posts

$item_name = $_POST['item_name'];
$item_author_id = $_SESSION['id'];
$item_location = $_POST['item_location'];
$item_description = $_POST['item_description'];
$item_type = $_POST['item_types'];
$extra_notes = $_POST['item_notes'];
$check_name = mysql_query("SELECT * WHERE item_name = '{$item_name}'");

if (mysql_num_rows($check_name) == 0){...

 

 

error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\WAMP\www\PP\itemprogram\create_item.php on line 14

 

trying to make it so it will check if that item name has already been used ot not, if not it will do the if and if no it will do the else.

Link to comment
https://forums.phpfreaks.com/topic/65213-solved-mysql_num_rows-issues/
Share on other sites

For security reasons I store my database connect and all that stuff in an external file and then define the database name as $link. So if you don't do that, change "$link" to the name of your database.

 

so  . . . change it to this:

 

$check_name = "SELECT * FROM tablename WHERE item_name = '" . $item_name . "'";

$result = mysql_query($check_name,$link) or die(mysql_error());

if (mysql_num_rows($result) == 1) {

}

 

Enter what you're checking for between the {} after the if statement. That should do it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.