fallenangel1983 Posted March 28, 2008 Share Posted March 28, 2008 Hey all, to cut to the chase: I have a table in which i successfully connect to via php. I has many columns with one named ID. I allow the user to enter an ID on a html form. if the ID they enter matches one in the table then the row is shown. that all works fine with this code: $ID=$_POST['ID']; $sql="select * from table where ID = '$ID'"; $result = blah blah $num = blah blah $i=0; while ($i < $num) { blah blah...... However what i want to do now is show an error when an ID that a user enters is NOT in the table. appreciate any help. Link to comment https://forums.phpfreaks.com/topic/98359-validation-support/ Share on other sites More sharing options...
metrostars Posted March 28, 2008 Share Posted March 28, 2008 I assume that $num will be the number of rows returned, so... $ID=$_POST['ID']; $sql="select * from table where ID = '$ID'"; $result = blah blah $num = blah blah if($num == "0") {echo "There were no results to return.";} else { $i=0; while ($i < $num) { blah blah......} Link to comment https://forums.phpfreaks.com/topic/98359-validation-support/#findComment-503353 Share on other sites More sharing options...
thebadbad Posted March 28, 2008 Share Posted March 28, 2008 if it's not, use mysql_num_rows: <?php if (mysql_num_rows($result) > 0) { // more than 0 rows } else { // no rows } ?> Link to comment https://forums.phpfreaks.com/topic/98359-validation-support/#findComment-503358 Share on other sites More sharing options...
fallenangel1983 Posted March 28, 2008 Author Share Posted March 28, 2008 brilliant. thankyou very much. it was the " " that was doing me in lol. i was using single quotation marks in the if statement. thanx as always. FallenAngel Link to comment https://forums.phpfreaks.com/topic/98359-validation-support/#findComment-503360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.