Forum Moderators: coopster
line 143 is " $num_rows=mysql_num_rows($mysql_result);" I have put stars next to the offending line of code. Can someone tell me what I have done wrong.
-------------------------------------------------------
$FULLNAME = empty($_POST['FULLNAME'])? die ("ERROR: Enter a Fullname") : mysql_escape_string($_POST['FULLNAME']);
$YOB = empty($_POST['YOB'])? die ("ERROR: Enter a Year of Brith if UNKNOWN put n/a") : mysql_escape_string($_POST['YOB']);
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// duplicate entry
$sql="SELECT * FROM `ADDRESS` WHERE FULLNAME='$FULLNAME'AND YOB='$YOB'";
$mysql_result=mysql_query($sql);
***** $num_rows=mysql_num_rows($mysql_result); ****
if ( $num_rows == 0) {
echo "No Duplicates Found<br>";
[edited by: jatar_k at 4:52 pm (utc) on Nov. 4, 2005]
[edit reason] reduced code dump [/edit]
// duplicate entry
$sql="SELECT * FROM `ADDRESS` WHERE FULLNAME='$FULLNAME'AND YOB='$YOB'";
$mysql_result=mysql_query($sql);
***** $num_rows=mysql_num_rows($mysql_result); ****
the query you are building there is causing an error. To return the proper error change your query line to
$mysql_result=mysql_query($sql) or die(mysql_error());
SELECT COUNT(*) FROM 'ADDRESS' WHERE FULLNAME='$FULLNAME' AND YOB='$YOB'
This does not force the SQL engine to return the rows themselves; just the count. (Even that is overkill. Ideally we would stop the query once more than one row is counted. I've seen elegant implementations of this idea on other platforms, but I don't know enough about MySQL to comment further.)