affordit Posted January 31, 2008 Share Posted January 31, 2008 Does anyone know whats wrong with this I am getting a blank page mysql_connect(mysql,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "Select name, email from test Where name = '$name' OR email = '$email'"; $results = mysql_query($query) or die(mysql_error()."<br /><br />".$query); $num=mysql_numrows($results); if ($_POST['name'] = ($results['name'])); { print "Name exists"; }elseif{ ($_POST['email'] = ($results['email'])); { print "Email exists"; exit(); } else{ mysql_connect(mysql,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO `test` (`id`, `company`, `name`, `address`, `city`, `state`, `zip`, `phone`, `acct_num`, `email`, `start_date`, `end_date`, `remind_date`, `lost_password`, `lost_password_answer`) VALUES (' ','$company','$name','$address','$city','$state','$zip','$phone','$acct_num','$email','$start_date','$end_date','$remind_date','$lost_password','$lost_password_answer')"; mysql_query($query) or die ("<table align='center' width='300'><td align='center'><tr><b>Email exists</b></td></tr></table>"); # if the user submitted a password if( isset($psword) ) { # get the user id $id = mysql_insert_id( ); # and insert the login details $query = "INSERT INTO login VALUES ('','$name','$psword','$email','$lost_password_answer','$end_date','$valid')"; mysql_query($query) or die ("The username you entered already exists, please choose another"); $to = "$email"; $subject = "Your Registration"; $message="Thank You for registering with us $name your password is $psword."; $headers = "From: webmaster@us@here.com"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "<br><table align='center' width='300'><td align='center'><tr><b>Your information has been saved and we have sent you an mail to $email with your password. To activate your account just login with your username $name and the password included in the Email.</b></td></tr></table>"; print "<table align='center' width='300'><td align='center'><tr><b><font color='#FF6600'>Your registration begins $start_date2<br>and will expire on $end_date2.<br>The first time you log in<a href ='first_login.php'>Do it here</a></b></td></tr></table>"; } else {print "We encountered an error sending your mail"; } } } mysql_free_result( $result ); mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/ Share on other sites More sharing options...
haku Posted February 1, 2008 Share Posted February 1, 2008 You should try indenting your code differently, you would see the problem instantly. It lies here: if ($_POST['name'] = ($results['name'])); { print "Name exists"; }elseif{ ($_POST['email'] = ($results['email'])); { print "Email exists"; exit(); } else{ Lets indent that code differently: if ($_POST['name'] = ($results['name'])); { print "Name exists"; } elseif { ($_POST['email'] = ($results['email'])); { print "Email exists"; exit(); } else { You didn't give any condition for your 'elseif' statement, which means that it always enters that. Then for the condition you did give, you used ($_POST['email'] = $results['email']). This (attempts) to assign the value of $results['email'] to $_POST['email'] (and fails, as this is not possible) rather than checking for equality. Use two equals signs to check for equality, not one. Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454918 Share on other sites More sharing options...
psychowolvesbane Posted February 1, 2008 Share Posted February 1, 2008 Are you sure you want the semi colons on the if statements as well??? ... if ($_POST['name'] = ($results['name'])); //<--Here { print "Name exists"; } elseif ($_POST['email'] = ($results['email'])); //<-- and Here { print "Email exists"; exit(); } else { ... Try removing them. Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454924 Share on other sites More sharing options...
haku Posted February 1, 2008 Share Posted February 1, 2008 heh, good point, I missed that altogether! Thats more likely your problem. Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454928 Share on other sites More sharing options...
affordit Posted February 1, 2008 Author Share Posted February 1, 2008 No Still a blank page. I been working at it still can't get it Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454938 Share on other sites More sharing options...
revraz Posted February 1, 2008 Share Posted February 1, 2008 Do you have error reporting turned on in your php.ini? Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454943 Share on other sites More sharing options...
affordit Posted February 1, 2008 Author Share Posted February 1, 2008 I believe it is when I screw other things up I get errors. I'm not sure and I don't know how to check the php is on the yahoo server Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454945 Share on other sites More sharing options...
revraz Posted February 1, 2008 Share Posted February 1, 2008 Try adding these two lines to the top of your code ini_set ('display_errors', 1); error_reporting (E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454950 Share on other sites More sharing options...
affordit Posted February 1, 2008 Author Share Posted February 1, 2008 Still a blank page Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454952 Share on other sites More sharing options...
revraz Posted February 1, 2008 Share Posted February 1, 2008 Your IF's only have one = if ($_POST['name'] = ($results['name'])); { should be if ($_POST['name'] == ($results['name'])); { Check your other one's as well. Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454956 Share on other sites More sharing options...
affordit Posted February 1, 2008 Author Share Posted February 1, 2008 OK added the ++ but still got a blank page so I took out the ; after each IF statement and goty these errors Notice: Use of undefined constant mysql - assumed 'mysql' in /sharon/submit_registration.php on line 72 Notice: Undefined variable: acct_num in /sharon/submit_registration.php on line 94 Notice: Undefined variable: remind_date in /sharon/submit_registration.php on line 94 Email exists Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454959 Share on other sites More sharing options...
affordit Posted February 1, 2008 Author Share Posted February 1, 2008 OK I meant == not ++ But now I got no errors but when I put in an email and Username that I know both exist in one of the records it goes past the if name part and goes right to Email exists. Here is the updated code mysql_connect(mysql,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "Select * from test Where name = '$name' OR email = '$email'"; $results = mysql_query($query) or die(mysql_error()."<br /><br />".$query); $num=mysql_numrows($results); if ($_POST['name'] == ($results['name'])) //<--Here { print "Name exists"; exit(); } elseif ($_POST['email'] == ($results['email'])) //<-- and Here { print "Email exists"; exit(); } else { Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454977 Share on other sites More sharing options...
revraz Posted February 1, 2008 Share Posted February 1, 2008 You need to use mysql_fetch_assoc in order to get the info from the DB. Also, this line is wrong $num=mysql_numrows($results); should be $num=mysql_num_rows($results); But you are not even checking $num so it's not doing anything. Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454982 Share on other sites More sharing options...
affordit Posted February 1, 2008 Author Share Posted February 1, 2008 I am not familiar with mysql_fetch_assoc Iguess I need to go and take a look at some documentation Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454986 Share on other sites More sharing options...
trq Posted February 1, 2008 Share Posted February 1, 2008 Also, you use two variables $name and $email in your query. Where are these defined? Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454995 Share on other sites More sharing options...
affordit Posted February 1, 2008 Author Share Posted February 1, 2008 They are set on a form. What it is is a registration form but when a new person registers I want to insure that the username and email are not duplicated in the login or clients tables. What happens is I insert into the clients table all the information and then insert into the login table the login info. The username and email are set to unique in the tables. Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454997 Share on other sites More sharing options...
revraz Posted February 1, 2008 Share Posted February 1, 2008 If the form is not on the same page, then they are not being passed so they won't get inserted into the DB. Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-454999 Share on other sites More sharing options...
trq Posted February 1, 2008 Share Posted February 1, 2008 If they are sent via a form using the POST method then the variables will be within the $_POSTarray, they don't just magically appear. What it is is a registration form but when a new person registers I want to insure that the username and email are not duplicated in the login or clients tables. Then your code ought to be.... <?php // connect to database if (isset($_POST['submit'])) { $name = mysql_real_escape_string($_POST['name']); $email = mysql_real_escape_string($_POST['email']); $sql = "SELECT name FROM test WHERE name = '$name' || email = '$email'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { echo "username or email already in use"; } else { // do registration } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-455003 Share on other sites More sharing options...
affordit Posted February 1, 2008 Author Share Posted February 1, 2008 I have no prob geting them to insert with this part of the code: $query = "INSERT INTO `test` (`id`, `company`, `name`, `address`, `city`, `state`, `zip`, `phone`, `acct_num`, `email`, `start_date`, `end_date`, `remind_date`, `lost_password`, `lost_password_answer`) VALUES (' ','$company','$name','$address','$city','$state','$zip','$phone','$acct_num','$email','$start_date','$end_date','$remind_date','$lost_password','$lost_password_answer')"; mysql_query($query) or die ("<table align='center' width='300'><td align='center'><tr><b>Email exists</b></td></tr></table>"); # if the user submitted a password if( isset($psword) ) { # get the user id $id = mysql_insert_id( ); # and insert the login details $query = "INSERT INTO login VALUES ('','$name','$psword','$email','$lost_password_answer','$end_date','$valid')"; mysql_query($query) or die ("The username you entered already exists, please choose another"); $to = "$email"; $subject = "Your Registration"; $message="Thank You for registering with us $name your password is $psword. You must go to affordit.us/sharon/first_login.php to log in so that your Email will be verified. Then you will be able to login on the normal login page. Thank you again and if you have any questions or concerns please feel free to contact us through our contact page. Patrick St. Charles Affordable Everything"; $headers = "From: webmaster@affordit.us"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "<br><table align='center' width='300'><td align='center'><tr><b>Your information has been saved and we have sent you an mail to $email with your password. To activate your account just login with your username $name and the password included in the Email.</b></td></tr></table>"; print "<table align='center' width='300'><td align='center'><tr><b><font color='#FF6600'>Your registration begins $start_date2<br>and will expire on $end_date2.<br>The first time you log in<a href ='first_login.php'>Do it here</a></b></td></tr></table>"; } else {print "We encountered an error sending your mail"; } } } mysql_free_result( $result ); mysql_close(); ?> That part works fine but when I try to add this to the top of the page: include("sharons_dbinfo.inc.php"); mysql_connect(mysql,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "Select * from test Where name = '$name' OR email = '$email'"; $results = mysql_query($query) or die(mysql_error()."<br /><br />".$query); $num=mysql_numrows($results); if ($_POST['name'] == ($results['name'])) //<--Here { print "Name exists"; exit(); } elseif ($_POST['email'] == ($results['email'])) //<-- and Here { print "Email exists"; exit(); } else { and enter values I know exist into the form it skips over the part where it checks the name and displays the resuut from the email check "EMAIL EXISTS" I don't get it. Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-455010 Share on other sites More sharing options...
trq Posted February 1, 2008 Share Posted February 1, 2008 As oyu yourself said, you best have a look at how mysql_fetch_assoc() works. mysql_query does not return a record. And please, can you use tags when posting code in the future? Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-455014 Share on other sites More sharing options...
affordit Posted February 1, 2008 Author Share Posted February 1, 2008 Yes I will thanks Quote Link to comment https://forums.phpfreaks.com/topic/88808-help/#findComment-455019 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.