satbir Posted August 12, 2013 Share Posted August 12, 2013 (edited) http://www.idea-ads.com/ <?phpinclude("../include/commands.php"); $sname = $_REQUEST['sname']; $name = $_REQUEST['name']; $pass = $_REQUEST['pass']; $repass = $_REQUEST['repass']; $query = "select * from signup where sname = '$sname'"; $result = mysql_query("$query", $con) or die ("error in result"); $row = mysql_fetch_array($result) or die (mysql_error()); if ($row) { echo $row['sname']; } else { echo "No record"; // this part is not working }?> Edited August 12, 2013 by satbir Quote Link to comment Share on other sites More sharing options...
Matic Posted August 12, 2013 Share Posted August 12, 2013 (edited) you should write it like this: $result = mysql_query($query); and if you want to get a row from your base: list($row) = mysql_fetch_row($result); EDIT: also, what are you trying to say in your if statement? if ($row) isn't enough. If you simply want to check if you have any rows in your signup table under the $sname, do it like so: if($row > 0) { //do stuff here } else { //do stuff here } Edited August 12, 2013 by Matic Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted August 12, 2013 Solution Share Posted August 12, 2013 the following line is causing your script to die() when there isn't a row to fetch. remove the or die (mysql_error()) part from this line - $row = mysql_fetch_array($result) or die (mysql_error()); mysql_fetch_array() returns a false value when there is no row to fetch. this triggers the or die() part AND since this isn't a mysql error, mysql_error() doesn't display anything. Quote Link to comment Share on other sites More sharing options...
satbir Posted August 12, 2013 Author Share Posted August 12, 2013 Thanks a lot Sir Quote Link to comment 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.