Jump to content

mysql_num_row doesn't work


mpsn

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/250308-mysql_num_row-doesnt-work/
Share on other sites

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!

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!

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!";

?>

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.