cadius Posted January 17, 2010 Share Posted January 17, 2010 Heya,Am a little confused as to whats going on here.Was working on this login/register code, and things had not been working well, looked it over a few times and found a few typos that had causes a few hiccups. All good. It got to the sending email bit and kept giving me the $error_reg message, 'We are unable to send... blah', so I added an echo ( echo $sql ) to see what the query was inputing.. low and behold, there was a blank at the $email, scratched my head and heh, hadnt added the $_POST, so added that and tried the page again, this time it said the $error_reg 'Sorry That email address... blah', which made no sense as it hadnt added anything to the table, looked up the table ( via phpmyadmin) and there was the row added, but the email field was actualy blank?So how did it match the query, if the info wasnt there? case 'reg': if ($email = '') { $error_reg = 'You have not entered an email address.'; } mysql_connect($hostname,$username,$sqlpass) OR DIE ('Cannot connect to server!' .mysql_error()); mysql_select_db($dbname) OR DIE ('Cannont connect to the database!' .mysql_error()); $email = trim($email); $email = mysql_real_escape_string($email); $sql = "SELECT email FROM game_user WHERE email = '$email'"; $result = mysql_query($sql); $stuff = mysql_num_rows($result); echo $stuff; if ($stuff > 0) { $error_reg = 'Sorry That email address is already registered.'; } else { $temppass = md5(uniqid(rand())); $sql = "INSERT INTO game_user (email,password) VALUES ($email,$pass)"; $result = mysql_query($sql); echo $sql; // <-- Using this to see the query if ($result) { $to = $email; $subject = "Grand Prince Confirmation"; $header = "From: Staff @ Grand Prince"; $message="Your activation link \r\n"; $message.="Click on the below link to activate your account \r\n"; $message.="http://www.haydiekeys.com/gp/confirm.php?id=$temppass"; $send = mail($to,$subject,$message,$header); $error_reg = 'An email has been sent, check your email to activate your account.'; } else { $error_reg = 'We are unable to send your confirmation email, please try again.'; } } break; Link to comment Share on other sites More sharing options...
cadius Posted January 17, 2010 Author Share Posted January 17, 2010 Just noticed the error with $pass and $temppass, but it still added it to the DB? Link to comment Share on other sites More sharing options...
Mencarta Posted January 17, 2010 Share Posted January 17, 2010 I would suggest using sha1() instead of md5(). Link to comment Share on other sites More sharing options...
cadius Posted January 17, 2010 Author Share Posted January 17, 2010 Okies,Back to the original problem, the email value isn't making an appearance. I've tried using no quotes, quotes and double quotes, but it doesnt make any difference. At the top of the page I've got: $email = $_POST['email']; In the html: <form method="post" action="index.php"> Your email:<input type="text" name="email" size="30" maxlength="64"><br /><input type="submit" name="submit" value="Register!" /><input type="hidden" name="type" value="reg"></form> And the php code again: switch ($type){ case 'reg': if ($email = '') { $error_reg = 'You have not entered an email address.'; } mysql_connect($hostname,$username,$sqlpass) OR DIE ('Cannot connect to server!' .mysql_error()); mysql_select_db($dbname) OR DIE ('Cannont connect to the database!' .mysql_error()); $email = trim($email); $email = mysql_real_escape_string($email); $sql = "SELECT email FROM game_user WHERE email = '$email'"; // <-- $email is coming up blank? $result = mysql_query($sql); $stuff = mysql_num_rows($result); echo $sql; // <-- Using this to see the query if ($stuff > 0) { $error_reg = 'Sorry That email address is already registered.'; } else { $temppass = md5(uniqid(rand())); $sql = "INSERT INTO game_user (email,password) VALUES ($email,$temppass)"; // <-- $email is coming up blank $result = mysql_query($sql); echo $sql; // <-- Using this to see the query if ($result) { $to = $email; $subject = "Grand Prince Confirmation"; $header = "From: Staff @ Grand Prince"; $message="Your activation link \r\n"; $message.="Click on the below link to activate your account \r\n"; $message.="http://www.haydiekeys.com/gp/confirm.php?id=$temppass"; $send = mail($to,$subject,$message,$header); $error_reg = 'An email has been sent, check your email to activate your account.'; } else { $error_reg = 'We are unable to send your confirmation email, please try again.'; } } break; case 'log': Link to comment Share on other sites More sharing options...
Err Posted January 17, 2010 Share Posted January 17, 2010 The way you have it right now, if you don't input an email it will output the error "You have not entered an email [...]" but your code will still query the database for email value of nothing. It will then find that $stuff is equal to 0, so then it will attempt to add nothing to your database. Put a ELSE statement after your first IF statement in your above code. It should help you, if not fix your problem. Link to comment Share on other sites More sharing options...
cadius Posted January 17, 2010 Author Share Posted January 17, 2010 Thanks RahXephon,That made sense so I added the else statement, but it still appears to be playing silly buggers. I cleared out the database, then refreshed the page and hit the register button without entering any input, it messaged that the confirmation email was sent, so I looked at the db, the insert had been done, but the email field was empty?If I then try to enter an email address and hit the button, it returns that the email is already in use.I've been looking this code over for a few hours now, proberbly too long, and cant see any other mistakes. Link to comment Share on other sites More sharing options...
Err Posted January 17, 2010 Share Posted January 17, 2010 What does your code look like now? Can you also include the relevant variables that you are using. Link to comment Share on other sites More sharing options...
cadius Posted January 17, 2010 Author Share Posted January 17, 2010 Well, this is the code here: <?phprequire_once('db.fun.php');$type = isset($_POST['type']) ? $_POST['type'] : '';$email = $_POST['email'];$pass = $_POST['pass'];var_dump($email); // Seeing if the email is posting$error_reg = '';$error_log = '';switch ($type){ case 'reg': if ($email = '') { $error_reg = 'You have not entered an email address.'; } else { mysql_connect($hostname,$username,$sqlpass) OR DIE ('Cannot connect to server!' .mysql_error()); mysql_select_db($dbname) OR DIE ('Cannont connect to the database!' .mysql_error()); $email = trim($email); $email = mysql_real_escape_string($email); $sql = "SELECT email FROM game_user WHERE email = '$email'"; // Email is coming up blank? $result = mysql_query($sql); $stuff = mysql_num_rows($result); echo $sql; // <-- Using this to see the query if ($stuff > 0) { $error_reg = 'Sorry That email address is already registered.'; } else { $temppass = md5(uniqid(rand())); $sql = "INSERT INTO game_user (email,password) VALUES ('$email','$temppass')"; $result = mysql_query($sql); echo $sql; // <-- Using this to see the query if ($result) { $to = $email; $subject = "Grand Prince Confirmation"; $header = "From: Staff @ Grand Prince"; $message="Your activation link \r\n"; $message.="Click on the below link to activate your account \r\n"; $message.="http://www.haydiekeys.com/gp/confirm.php?id=$temppass"; $send = mail($to,$subject,$message,$header); $error_reg = 'An email has been sent, check your email to activate your account.'; } else { $error_reg = 'We are unable to send your confirmation email, please try again.'; } } } break; case 'log': $error_log = 'Log is here!'; break; case ''; $error_txt = 'Working fine!'; end;}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link rel="stylesheet" type="text/css" href="style.css" /></head><body><h1>Welcome!</h1><p>Welcome to my little game.</p><p><div class="error_text"><?php echo $error_reg; ?></div> <form action="index.php" method="post"> Your email:<input type="text" name="email" size="30" maxlength="255"><br /> <input type="submit" name="submit" value="Register!" /> <input type="hidden" name="type" value="reg"> </form></p><p><div class="error_text"><?php echo $error_log; ?></div> <form method="post" action="index.php"> Your email:<input type="text" name="email" size="30" maxlength="255"><br /> Your Password:<input type="password" name="pass" size="30" maxlength="255"><br /> <input type="submit" name="login" value="Log In" /> <input type="hidden" name="type" value="log" /><div class="error_text"><?php echo $error_txt; ?></div></body></html> Link to comment Share on other sites More sharing options...
Err Posted January 17, 2010 Share Posted January 17, 2010 I can't believe I missed this: if ($email = ''). I think what you were aiming for is if ($email == '') with the two equal signs. Try out that change. Here's a tip, if ($var == '') is the same as if (!$var), it certainly was helpful for me when I found that out. Link to comment Share on other sites More sharing options...
cadius Posted January 17, 2010 Author Share Posted January 17, 2010 Thanks again RahXephon,Thats was it, I should have picked that one up myself. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.