princeofpersia Posted July 18, 2011 Share Posted July 18, 2011 Hi guys, I have a registeration page where i get two errors for mysql_num_rows and my_sql_fetch arrays, I have checked the connection and it works fine (I dont get any error for that) and my table name is users with this fields user_id user_email user_password country and the error i get is for both that mysql_fetch_array(): supplied argument is not a valid MySQL result resource in..... and Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in.... could you help me with this please to see where the mistake is? Thank you all in advance <?php //ob ob_start(); //session session_start(); //connect to database $error = "Problem connecting"; mysql_connect('localhost','','') or die($error); mysql_select_db('') or die($error); ?> <!--Header starts here--> <?php include ('../../include/content/header.php'); include ('../../include/config/detect.php'); ?> <div id="breadcrumbs"><div id="text"><?php include($_SERVER['DOCUMENT_ROOT']."/backlinks.php"); ?></div></div><br/> <div id="pagetitleholder"><div id="pagetitle"><h1>Create Account</h1></div></div> <!--Main body begins here--> <div id="maincontentbody"> <div id="regformbody"> <h2>Why Register? </h2> <div id="blueline"></div><br/> <?php if (isset($_POST['create_account']) && isset($_POST['create_account'])) { $myname=mysql_real_escape_string($_POST['firstname']); $mylastname=mysql_real_escape_string($_POST['lastname']); $myemail=mysql_real_escape_string($_POST['email']); $myconfirmemail=mysql_real_escape_string($_POST['confirmemail']); $mypassword=mysql_real_escape_string($_POST['password']); $confirmpassword=mysql_real_escape_string($_POST['confirmpassword']); if(!$myname || !$mylastname || !$myemail || !$myconfirmemail || !$mypassword || !$confirmpassword){echo "<div id='regerror'>All fields are required</div>";} else ///// if (ereg('[0-9]', $myname)) {echo "<div id='regerror'>First Name should contain only letters</div>";} else if (ereg('[0-9]', $mylastname)) {echo "<div id='regerror'>Last Name should contain only letters</div>";} else if(strlen($myname)<3){echo "<div id='regerror'>Your first name should contain 3 or more letters</div>";} else if(strlen($mylastname)<3){echo "<div id='regerror'>Your first name should contain 3 or more letters</div>";} else ///// Check email validity if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $myemail)) { echo "<div id='regerror'>This email is not valid, Please insert a valid email address!</div>"; } else ////// Check Email Address ////////// if ($myemail != $myconfirmemail) {echo "<div id='regerror'>Your emails do not match, Please try again!</div>";} //////////////////////////// else echo"$myemail"; $ge=sprintf("SELECT * FROM users WHERE user_email='%s'", mysql_real_escape_string($myemail)); while($row=mysql_fetch_array($ge)){ $myemail= $row['user_email']; echo"$myemail"; } if (mysql_num_rows($ge)==1){echo "<div id='regerror'>This email has been already registered in our records, Please click here to request a passoword</div>";} if ($mypassword != $confirmpassword) {echo "<div id='regerror'>Your Passwords do not match, Please try again!</div>";} else $firstname=ucfirst($myname); $lastname=ucfirst($mylastname); } ?> <p><form class="regform" action="" method="post" name="regform"> <label for="firstname">First Name</label><input type="text" name="firstname" title="Enter your first name"/><br/> <label for="lastname">Last Name</label><input type="text" name="lastname" title="Enter your last name"/><br/> <label for="email">Email</label><input type="email" name="email" title="Enter your email address"/><br/> <label for="confirmemail">Confirm Your Email</label><input type="email" name="confirmemail" title="Confirm your email address"/><br/> <label for="password">Choose a Password</label><input type="text" name="password" title="Must be 6 to 15 characters"/><br/> <label for="confirmpassword">Confirm a Password</label><input type="text" name="confirmpassword" title="Must be 6 to 15 characters"/><br/> <p><div id="acceptterms">By clicking on the "Create Your Account" button below, I certify that I have read and agree to JPG <a href="terms/terms.php" title="Terms and Conditions" target="_new">Terms and Conditions</a> and <a href="/terms/privacy.php" title="Privacy Policy" target="_new">Privacy Policy</a>.</div></p> <div id="regbtncontainer"> <input type="submit" name="create_account" value="Create an Account" class="regbtn"/> </div> </form></p> </div> </div> <!--Main body ends here--> <!--Footer starts here--> <?php include ('../../include/content/footer.php') ?> <?php ob_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/242250-php-mysql-num-errors/ Share on other sites More sharing options...
TeNDoLLA Posted July 18, 2011 Share Posted July 18, 2011 You never run your query there $ge=sprintf("SELECT * FROM users WHERE user_email='%s'", mysql_real_escape_string($myemail)); while($row=mysql_fetch_array($ge)){ You actually need to use mysql_query() to run the query and get some results. Quote Link to comment https://forums.phpfreaks.com/topic/242250-php-mysql-num-errors/#findComment-1244069 Share on other sites More sharing options...
princeofpersia Posted July 18, 2011 Author Share Posted July 18, 2011 Thanks but what do u mean? if this is not a good way then how i should approach it? Quote Link to comment https://forums.phpfreaks.com/topic/242250-php-mysql-num-errors/#findComment-1244073 Share on other sites More sharing options...
TeNDoLLA Posted July 18, 2011 Share Posted July 18, 2011 Theres nothing wrong in the approach, you just never run the query u define. $query = sprintf("SELECT * FROM users WHERE user_email='%s'", mysql_real_escape_string($myemail)); $result = mysql_query($query); while($row = mysql_fetch_array($result)){ //.. and so on.. Quote Link to comment https://forums.phpfreaks.com/topic/242250-php-mysql-num-errors/#findComment-1244074 Share on other sites More sharing options...
princeofpersia Posted July 18, 2011 Author Share Posted July 18, 2011 Thanks, I have changed it as you mentioned but still getting the same error. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/242250-php-mysql-num-errors/#findComment-1244078 Share on other sites More sharing options...
TeNDoLLA Posted July 18, 2011 Share Posted July 18, 2011 Try adding or die(mysql_error()) in your queries. Your queries are failing for some reason. You can also try to echo out the query before running it to see if it is valid syntax. Quote Link to comment https://forums.phpfreaks.com/topic/242250-php-mysql-num-errors/#findComment-1244087 Share on other sites More sharing options...
princeofpersia Posted July 18, 2011 Author Share Posted July 18, 2011 this is what i have done and this is the error i get, error2 $mygets=sprintf("SELECT * FROM users WHERE user_email='%s'", mysql_real_escape_string($myemail)) or die('Error 1'); $result = mysql_query($mygets) or die('Error 2'); Quote Link to comment https://forums.phpfreaks.com/topic/242250-php-mysql-num-errors/#findComment-1244088 Share on other sites More sharing options...
TeNDoLLA Posted July 18, 2011 Share Posted July 18, 2011 Replace 'Error 2' and 'Error 1' with mysql_error() to actually see the errors what mysql is giving. Now you define your own errors instead. Quote Link to comment https://forums.phpfreaks.com/topic/242250-php-mysql-num-errors/#findComment-1244091 Share on other sites More sharing options...
princeofpersia Posted July 18, 2011 Author Share Posted July 18, 2011 thanks, this is what i get .commysql_error() Quote Link to comment https://forums.phpfreaks.com/topic/242250-php-mysql-num-errors/#findComment-1244095 Share on other sites More sharing options...
princeofpersia Posted July 18, 2011 Author Share Posted July 18, 2011 Unknown column 'user_email' in 'where clause' Quote Link to comment https://forums.phpfreaks.com/topic/242250-php-mysql-num-errors/#findComment-1244098 Share on other sites More sharing options...
TeNDoLLA Posted July 18, 2011 Share Posted July 18, 2011 So there's no column called 'user_email' in your users table in the database. See what the columnis called and fix your query accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/242250-php-mysql-num-errors/#findComment-1244102 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.