0

this has been driving me nuts. It should work. $value2 is an array with two strings in it. mysql_num_rows should return 1 row for each string. instead it returns zero. I simplified it below and cannot get it to work. it should echo "equals one".

$value2 = $_POST['topic'];
               
				foreach($value2 as $key) {
				mysql_connect("localhost", "USER", "PWD");
mysql_select_db("ustackc1_Ustack");
	  
	  
	  	$updatestable = mysql_query("SELECT * FROM `Stacks` WHERE keywords LIKE '%$key%' ORDER BY id DESC LIMIT 1")or die (mysql_error());
			
			$upnum = mysql_num_rows($updatestable); 
				if($upnum==0){ echo "equals zero"; } else { echo "equals one";}
				
				}

Edited by Ezzaral: Removed private data

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Kieran Y5
0

For the future, I would recommend that you don't say your mysql password. You can open a connection to a mysql server through the web.

Try this:

$value2 = $_POST['topic'];
               
foreach($value2 as $key)
{
    $con = mysql_connect("localhost", "USER", "PWD");
    mysql_select_db("ustackc1_Ustack", $con);
	  
    $updatestable = mysql_query("SELECT * FROM `Stacks` WHERE keywords LIKE '%".$key."%' ORDER BY id DESC LIMIT 1", $con) or die (mysql_error());
			
    $upnum = @mysql_num_rows($updatestable); 
    if($upnum==0)
    {
        echo "equals zero";
    }
    else
    {
        echo "equals one";
    }

}

Edited by Kieran Y5: Removed private data from code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.