EDIT
SO I figured out a fix. I replaced the while statement with an if and it worked perfectly. Thanks to everyone who helped out!
I was making a sign up page when this error came up ( I’m still kind of new to programming and php so this might explain what the error is and I just don’t know)
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Users/Jacob/Sites/website/postregister.php on line 22
Here’s my code:
<!-- start sign up form -->
<?php
include("config.php");
$firstname = mysql_real_escape_string($_REQUEST['firstname']);
$lastname = mysql_real_escape_string($_REQUEST['lastname']);
$email = mysql_real_escape_string($_REQUEST['email']);
$birthyear = mysql_real_escape_string($_REQUEST['birthyear']);
$city = mysql_real_escape_string($_REQUEST['city']);
$address = mysql_real_escape_string($_REQUEST['address']);
$state = mysql_real_escape_string($_REQUEST['state']);
$phone = mysql_real_escape_string($_REQUEST['phone']);
$password = mysql_real_escape_string($_REQUEST['password']);
$zipcode= mysql_real_escape_string($_REQUEST['zipcode']);
$active = 0;
$hash = md5( rand(0,1000) ); // Generate random 32 character hash and assign it to a local variable.
$sql= mysql_query("INSERT INTO member (firstname, lastname, email, phone, city, state, address, zipcode, password, hash, active)
VALUES
('$firstname','$lastname','$email','$phone', '$city', '$state','$address', '$zipcode', '$password', '$hash', '$active')")or die(mysql_error());
while($row == mysql_fetch_array($sql)){
$to = $email; //Send email to our user
$subject = 'Signup | Verification'; //// Give the email a subject
$message = '
Thanks for signing up!<br/>
Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.<br/>
------------------------------------------------------------------------------<br/>
Email: '.$email.'<br/>
Password: '.$password.'<br/>
------------------------------------------------------------------------------
<a href="http://localhost/~jacob/pages/verify.php?email='.$email.'&hash='.$hash.'">Please Click Here to Activate Your Account</a>
'; // Our message above including the link
$headers = "From: customersupport@example.com\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers); // Send the email
}
?>
<form action="postregister.php" method="post">
<label for="firstname">First Name:</label><br/>
<input type="text" name="firstname" value="" size='90' style='height:20px;' /><br/><br/>
<label for="lastname">Last Name:</label><br/>
<input type="text" name="lastname" value="" size='90' style='height:20px;'/><br/><br/>
<label for="email">Email:</label><br/>
<input type="text" name="email" value="" size='90' style='height:20px;'/><br/><br/>
<label for="birthyear">Birthyear:</label><br/>
<input type="text" name="birthyear" value="" size='90' style='height:20px;'/><br/><br/>
<label for="city">City:</label><br/>
<input type="text" name="city" value="" size='90' style='height:20px;'/><br/><br/>
<label for="phone">Phone:</label><br/>
<input type="text" name="phone" value="" size='90' style='height:20px;'/><br/><br/>
<label for="address">Address:</label><br/>
<input type="text" name="address" value="" size='90' style='height:20px;'/><br/><br/>
<label for="zipcode">Zipcode:</label><br/>
<input type="text" name="zipcode" value="" size='90' style='height:20px;'/><br/><br/>
<label for="State">State:</label><br/>
<input type="text" name="state" value="" size='90' style='height:20px;'/><br/><br/>
<label for="password">Password:</label><br/>
<input type="password" name="password" value="" size='90' style='height:20px;'/><br/><br/>
<input type="submit" class="submit_button" value="Sign up" />
</form>
Any help would be GREATLY appreciated. Thanks!
It looks like your query is returning false. I would imagine there’s an error with your database connection. Try printing your query and running it manually on your database to confirm it’s running properly. You can also just try a simple:
And see what happens. I imagine this will error out too. Check your
include("config.php");and be sure your DB link is set up and working properly. To confirm your $sql isn’t getting a valid result you can try dumping it out and seeing what type it is using either print_r or var_dump. Good luck.