kidzkit Posted July 7, 2008 Share Posted July 7, 2008 Can anyone help me. I am trying to error trap. This is my pseudo code if no records arent there then display and error and if records are returned then i want to tell the user they are in the database. Any ideas? here is my code that i am trying to figure out $result = mysql_query("SELECT * FROM users") or die(mysql_error()); $row = mysql_fetch_array($result); if (($row['username'] < 0 ) || ($row['pass'] < 0 )) { $errors += 1; } if($errors > 0) { echo "Please go back and make corrections"; } else { echo "User is in the database"; } some help would be nice Link to comment https://forums.phpfreaks.com/topic/113639-solved-error-trapping-from-databases/ Share on other sites More sharing options...
br0ken Posted July 7, 2008 Share Posted July 7, 2008 You need to use the function mysql_num_rows($result). This returns the amount of rows returned by the last query. Link to comment https://forums.phpfreaks.com/topic/113639-solved-error-trapping-from-databases/#findComment-584011 Share on other sites More sharing options...
kidzkit Posted July 8, 2008 Author Share Posted July 8, 2008 This is what i got now but it keeps jumping to the else statement whether the person is there or not $result = mysql_query("SELECT * FROM users") or die(mysql_error()); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); if ($count == 1) { echo "User is in the databases"; } else { echo "Please go back and make corrections"; } i am fairly new to this stuff Link to comment https://forums.phpfreaks.com/topic/113639-solved-error-trapping-from-databases/#findComment-584108 Share on other sites More sharing options...
DarkWater Posted July 8, 2008 Share Posted July 8, 2008 You have no WHERE clause so the $count is going to be much greater than 1. =/ Link to comment https://forums.phpfreaks.com/topic/113639-solved-error-trapping-from-databases/#findComment-584112 Share on other sites More sharing options...
kidzkit Posted July 8, 2008 Author Share Posted July 8, 2008 can you help me write a working code to? i been workin on this shit all day hahahaha. here is my full code. If maybe you could fix anything you see wrong <?php //phpinfo(); $name = $_POST["name"]; $pass = $_POST["pass"]; $errors = 0; $con = mysql_connect("****","****","****"); $creDB = "CREATE DATABASE login"; $db = mysql_select_db("login", $con); $result = mysql_query($creDB); if (!$db) { die(mysql_error()); } if (!$con) { die(mysql_error()); } mysql_select_db('login') or die('Cannot select database'); $result = mysql_query("SELECT * FROM users") or die(mysql_error()); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); if ($count != 1) { echo "User is in the databases"; } else { echo "Please go back and make corrections"; } Link to comment https://forums.phpfreaks.com/topic/113639-solved-error-trapping-from-databases/#findComment-584117 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.