Jump to content

PHP MYSQL NUM Errors


princeofpersia

Recommended Posts

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 :rtfm:

 

 

<?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(); ?>



Link to comment
https://forums.phpfreaks.com/topic/242250-php-mysql-num-errors/
Share on other sites

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..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.