mpsn Posted November 2, 2011 Share Posted November 2, 2011 Hi, I am trying to get the previous id for the table xdocument, but browser outputs this warning: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given for this code: <?php //HELPER FCN used by FCN: writeXMLtoDBviaDOM function mysql_next_id($table) { $result = mysql_query('SHOW TABLE STATUS LIKE "'.$table.'"'); $rows = mysql_fetch_assoc($result); return $rows['Auto_increment']; } //TEST RUN: $_filePath="C:\dir\email.xml"; $node=basename($_filePath); $dom=new DOMDocument(); $dom->load($node); $labelPath=array(); mysql_connect("localhost","root"); mysql_select_db("dummydpev"); $isXdocExist=mysql_query("SELECT (file_Path,file_Name) FROM xdocument WHERE file_Path='$_filePath' AND file_Name='$node'"); $docId=0; if(mysql_num_rows($isXdocExist)==0) { mysql_query("INSERT INTO xdocument (file_Path,file_Name) VALUES ('$_filePath','$node')"); $docId=mysql_next_id("xdocument")-1; } else $docId=mysql_next_id("xdocument")-1; writeXMLtoDBViaDOM($dom->documentElement,$labelPath,$docId,$_filePath); ?> So I think my problem is with the multiple WHERE clause conditions, can I do it like what I have above? Any help much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/250308-mysql_num_row-doesnt-work/ Share on other sites More sharing options...
Pikachu2000 Posted November 2, 2011 Share Posted November 2, 2011 mysql_num_rows() works just fine. mysql_query returns a resource result on success, or a boolean FALSE on failure. mysql_error should give you information as to why your query is failing. Quote Link to comment https://forums.phpfreaks.com/topic/250308-mysql_num_row-doesnt-work/#findComment-1284338 Share on other sites More sharing options...
mpsn Posted November 2, 2011 Author Share Posted November 2, 2011 Why does it still keep adding the SAME entry when I refresh the page? I though the condition below $isXdocExist=mysql_query("SELECT (file_Path,file_Name) FROM xdocument WHERE file_Path='$_filePath' AND file_Name='$node'"); $docId=0; if(mysql_num_rows($isXdocExist)==0) { //INSERT INTO table xdocument will ensure if I refresh browser, script SHOULDN'T re-enter same entry or is it b/c my query ($isXdocExist) is all condisered UNIQUE b/c of different primary keys? Any help much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/250308-mysql_num_row-doesnt-work/#findComment-1284341 Share on other sites More sharing options...
mpsn Posted November 2, 2011 Author Share Posted November 2, 2011 Ok, I tried to put in UNIQUE, but now it doesn't insert at all into db table. <?php mysql_connect("localhost","root"); mysql_select_db("dummydpev2"); //$isXdocExist=mysql_query("SELECT (file_Path,file_Name) FROM xdocument WHERE file_Path='$_filePath' AND file_Name='$node'"); $docId=0; $title="cashier"; $name="bob"; $isToyEntryExist=mysql_query("SELECT (title,name) FROM toy WHERE title='$title'"); //INSERT entry if NOT in table if(mysql_num_rows($isToyEntryExist)==0) { mysql_query("INSERT INTO toy (title,name) UNIQUE VALUES ('$title','$name')"); } else print "Already in db dummpdpev2.toy!"; ?> Please help! Quote Link to comment https://forums.phpfreaks.com/topic/250308-mysql_num_row-doesnt-work/#findComment-1284379 Share on other sites More sharing options...
mpsn Posted November 2, 2011 Author Share Posted November 2, 2011 Yes, it is the checking of multiple fields in WHERE clause that causes problems with the mysql_num_rows, please help! Quote Link to comment https://forums.phpfreaks.com/topic/250308-mysql_num_row-doesnt-work/#findComment-1284387 Share on other sites More sharing options...
Drummin Posted November 2, 2011 Share Posted November 2, 2011 This looks like it should work. <?php mysql_connect("localhost","root"); mysql_select_db("dummydpev2"); //$isXdocExist=mysql_query("SELECT (file_Path,file_Name) FROM xdocument WHERE file_Path='$_filePath' AND file_Name='$node'"); $docId=0; $title="cashier"; $name="bob"; $isToyEntryExist=mysql_query("SELECT title,name FROM toy WHERE title='$title'"); //INSERT entry if NOT in table if(mysql_num_rows($isToyEntryExist)==0) { mysql_query("INSERT INTO toy (title,name) VALUES('$title','$name')"); } else print "Already in db dummpdpev2.toy!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/250308-mysql_num_row-doesnt-work/#findComment-1284399 Share on other sites More sharing options...
mpsn Posted November 2, 2011 Author Share Posted November 2, 2011 No, I'm saying that it doesn't work if I am trying to check if duplicate record/entry across multiple columns. Help! Quote Link to comment https://forums.phpfreaks.com/topic/250308-mysql_num_row-doesnt-work/#findComment-1284411 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.