mpsn Posted October 30, 2011 Share Posted October 30, 2011 Hi, I just want to know how to check if a row/record already exists for a given table, but this code gives me message in browser: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in myTest.php This is the the snippet I am running: <?php $connxn=mysql_connect("localhost","root"); $db=mysql_select_db("siliconvalley"); $toyNodePath="#document/siliconValleyHELLO"; $queryA=mysql_query("SElECT FROM pathexpress (path_express) WHERE path_express='$toyNodePath'");//make sure AT MOST ONE ROW EXISTS!! if(mysql_num_rows($queryA)==1) print "ALREADY IN table pathexpress!"; else { mysql_query("INSERT INTO pathexpress (path_express) VALUES ('$toyNodePath')"); print "ADDED $toyNodePath to table pathexpress!"; } ?> Please, any help is greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/250085-how-to-check-if-a-recordrow-exists-in-a-table/ Share on other sites More sharing options...
mpsn Posted October 30, 2011 Author Share Posted October 30, 2011 I got it working, I just had the arrangements of the query mixed up Link to comment https://forums.phpfreaks.com/topic/250085-how-to-check-if-a-recordrow-exists-in-a-table/#findComment-1283388 Share on other sites More sharing options...
Psycho Posted October 30, 2011 Share Posted October 30, 2011 A better choice would be to use ON DUPLICATE KEY and just do the INSERT query. That way you only need one query. Link to comment https://forums.phpfreaks.com/topic/250085-how-to-check-if-a-recordrow-exists-in-a-table/#findComment-1283389 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.