astralaaron Posted May 13, 2007 Share Posted May 13, 2007 this code was working perfectly , somehow something changed and it stopped working!it it suposed to make sure that both password fields match and both email fieldsit is also suposed to make sure no one with the same email or username can register twiceit is basically skipping my if / else if's and just sending the confirmation email no matter whative been trying to fix it for 2 hours now, someone please help!i cant believe this stopped working like that.. it was working fine! <?phpsession_start();ob_start();$conn = mysql_connect("localhost","root","*******")if (!$conn) { die('Could not connect: ' . mysql_error()); } mysql_select_db("vikingbjj", $conn);$tbl_name="temp_members_db";$confirm_code=md5(uniqid(rand()));$myusername=$_POST['myusername'];$mypassword=$_POST['mypassword'];$mypassword2=$_POST['mypassword2'];$user=$_POST['myusername'];$myemail=$_POST['myemail'];$myemail2=$_POST['myemail2']; if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i", $myemail)) { header("location:http://localhost/vikingbjj/user/emailerror.php");} else if (!preg_match('{[0-9a-zA-Z]}', $myusername)) { header('location:http://localhost/vikingbjj/user/nameerror.php'); } else if ($myemail != $myemail2) { header('location:http://localhost/vikingbjj/user/emailerror.php');} else if ($mypassword != $mypassword2) { header('location:http://localhost/vikingbjj/user/passworderror.php');} else {$sql="SELECT * FROM members WHERE user=$user";$sql2="SELECT * FROM members WHERE email=$myemail";$result=mysql_query($sql);$result2=mysql_query($sql2);$count=mysql_num_rows($result);$count2=mysql_num_rows($result2);if($count > 0){ header("location:http://localhost/vikingbjj/user/existserror.php");} else if ($count2 > 0){ header("location:http://localhost/vikingbjj/user/mailerror.php");} if ($count == 0 and $count2 == 0){ $sql3="INSERT INTO $tbl_name (confirm_code, username, password, email, user)VALUES('$confirm_code','$myusername','$mypassword','$myemail','$user')";if (!mysql_query($sql3,$conn)) { die('Error: ' . mysql_error()); }$to=$myemail;$subject="VikingBJJ.com confirmarion email";$header="from: vikingBJJ.com <webmaster@vikingbjj.com>";$message ="You registerd the name:$myusername\r\n";$message.="password:$mypassword\r\n";$message.="Be sure to write this information down, it is encrypted when entered into our database and cannot be retrieved\r\n";$message.="\r\n";$message.="Click on this link to activate your account \r\n";$message.="http://localhost/vikingbjj/user/confirmation.php?passkey=$confirm_code";$sentmail = mail($to,$subject,$message,$header);}// if your email succesfully sentif($sentmail){header("location:http://localhost/vikingbjj/user/confirm.php");}else {echo "Cannot send Confirmation link to your e-mail address";}mysql_close($conn);ob_end_flush();?> Link to comment Share on other sites More sharing options...
MildewMan1 Posted May 13, 2007 Share Posted May 13, 2007 looks like you've forgotten a ; in your code try changing $conn = mysql_connect("localhost","root","*******") to $conn = mysql_connect("localhost","root","*******"); Link to comment Share on other sites More sharing options...
astralaaron Posted May 13, 2007 Author Share Posted May 13, 2007 looks like you've forgotten a ; in your code try changing$conn = mysql_connect("localhost","root","*******") to $conn = mysql_connect("localhost","root","*******"); i dont know why in the codebox it doesnt have that, but in my code i do have that. its not the problem Link to comment Share on other sites More sharing options...
MildewMan1 Posted May 13, 2007 Share Posted May 13, 2007 just for clarification, which of the if/else statements is it skipping? Link to comment Share on other sites More sharing options...
astralaaron Posted May 13, 2007 Author Share Posted May 13, 2007 its now just letting me register with the same email / username more than onceit was skipping all of them, but i just restarted my server and now it is just skipping this part $sql="SELECT * FROM members WHERE user=$user";$sql2="SELECT * FROM members WHERE email=$myemail";$result=mysql_query($sql);$result2=mysql_query($sql2);$count=mysql_num_rows($result);$count2=mysql_num_rows($result2);if($count > 0){ header("location:http://localhost/vikingbjj/user/existserror.php");} else if ($count2 > 0){ header("location:http://localhost/vikingbjj/user/mailerror.php");} Link to comment Share on other sites More sharing options...
MildewMan1 Posted May 13, 2007 Share Posted May 13, 2007 the only reason it should skip the first 2 statements is if $count and $count2 are not > 0 according to your code. This might not be of a lot of help, but I would suggest looking at $sql="SELECT * FROM members WHERE user=$user";$sql2="SELECT * FROM members WHERE email=$myemail";$result=mysql_query($sql);$result2=mysql_query($sql2);$count=mysql_num_rows($result);$count2=mysql_num_rows($result2); to find out why your count variables aren't increasing. Try commenting out the mail part and just do an echo of what $count and $count2's values are. Maybe it will help you with locating the error. I'll keep looking at it and see if I notice anything else. Maybe someone else can spot it before me Link to comment Share on other sites More sharing options...
astralaaron Posted May 13, 2007 Author Share Posted May 13, 2007 the only reason it should skip the first 2 statements is if $count and $count2 are not > 0 according to your code. This might not be of a lot of help, but I would suggest looking at $sql="SELECT * FROM members WHERE user=$user";$sql2="SELECT * FROM members WHERE email=$myemail";$result=mysql_query($sql);$result2=mysql_query($sql2);$count=mysql_num_rows($result);$count2=mysql_num_rows($result2); to find out why your count variables aren't increasing. Try commenting out the mail part and just do an echo of what $count and $count2's values are. Maybe it will help you with locating the error. I'll keep looking at it and see if I notice anything else. Maybe someone else can spot it before me i will give it a try, but ive looked over that code a dozen times i dont see how that could be the problem!thanks though Link to comment Share on other sites More sharing options...
MildewMan1 Posted May 13, 2007 Share Posted May 13, 2007 I looked at some of the code I have dealing with mysql (I'm still a big newbie at it myself), but try this and maybe it will work for you. $sql="SELECT * FROM members WHERE user=$user";$sql2="SELECT * FROM members WHERE email=$myemail";$result=mysql_query($sql,$conn);$result2=mysql_query($sql2,$conn);$count=mysql_num_rows($result,$conn); //not sure about this, but maybe you need it here too$count2=mysql_num_rows($result2,$conn); Link to comment Share on other sites More sharing options...
astralaaron Posted May 13, 2007 Author Share Posted May 13, 2007 it just gave me this now...Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\vikingbjj\user\newidcheck.php on line 35Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\vikingbjj\user\newidcheck.php on line 36 Link to comment Share on other sites More sharing options...
MildewMan1 Posted May 13, 2007 Share Posted May 13, 2007 try taking the $conn out of the mysql_num_rows statementsTake a look at this link, maybe it will help Link to comment Share on other sites More sharing options...
astralaaron Posted May 13, 2007 Author Share Posted May 13, 2007 i tried this : <?phpsession_start();ob_start();$conn = mysql_connect("localhost","root","");if (!$conn) { die('Could not connect: ' . mysql_error()); } mysql_select_db("vikingbjj", $conn);$tbl_name="temp_members_db";$confirm_code=md5(uniqid(rand()));$myusername=$_POST['myusername'];$mypassword=$_POST['mypassword'];$mypassword2=$_POST['mypassword2'];$user=$_POST['myusername'];$myemail=$_POST['myemail'];$myemail2=$_POST['myemail2'];$result=mysql_query("SELECT * FROM members WHERE user=$user", $conn);$result2=mysql_query("SELECT * FROM members WHERE email=$myemail", $conn);$count=mysql_num_rows($result);$count2=mysql_num_rows($result2); echo "$count";echo "$count2";mysql_close($conn);ob_end_flush();?> it just keeps returning the same error Link to comment Share on other sites More sharing options...
MildewMan1 Posted May 13, 2007 Share Posted May 13, 2007 One thing I notice, and maybe you have a reason for it and it's not related to this problem, is you have 2 variables that hold the same information $myusername=$_POST['myusername'];$user=$_POST['myusername']; I am still thinking of another solution to your problem that may work. Just thinking of how to code it Gimme a little bit to think about it. Link to comment Share on other sites More sharing options...
astralaaron Posted May 13, 2007 Author Share Posted May 13, 2007 man now I am getting all of these errorsWarning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\vikingbjj\user\newidcheck111.php on line 35Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\vikingbjj\user\newidcheck111.php on line 36Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\vikingbjj\user\newidcheck111.php on line 48Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@localhost' at line 1seems like I am just making it worse!! Link to comment Share on other sites More sharing options...
astralaaron Posted May 13, 2007 Author Share Posted May 13, 2007 now I am not getting errors, it is just skipping this part$result=mysql_query("SELECT * FROM members WHERE user=$myusername");$result2=mysql_query("SELECT * FROM members WHERE email=$myemail2");$count=mysql_num_rows($result);$count2=mysql_num_rows($result2); if($count > 0){ header("location:http://localhost/vikingbjj/user/existserror.php");} else if ($count2 > 0){ header("location:http://localhost/vikingbjj/user/mailerror.php");} Link to comment Share on other sites More sharing options...
MildewMan1 Posted May 13, 2007 Share Posted May 13, 2007 you could try something like $result = mysql_query("SELECT * FROM members WHERE user=$user");$result2 = mysql_query("SELECT * FROM members WHERE user=$myemail");$count = count($result);$count2 = count($result2);for ($i =0; $i < $count; $i++){ if (strcmp($user, $result[$i]) == 0) { die("This name already exists!"); } else if (strcmp($myemail, $result2[$i]) == 0) { die("This e-mail already exists!"); }} This code probably isn't perfect and may need some tweaking, but it might help you compare your input versus your database. Hope this helps at least some. I feel I've done more damage than good Link to comment Share on other sites More sharing options...
astralaaron Posted May 13, 2007 Author Share Posted May 13, 2007 Oh wow.. it is working nowall I needed was some ( ' )'s$result=mysql_query("SELECT * FROM members WHERE user=$myusername");$result2=mysql_query("SELECT * FROM members WHERE email=$myemail2");needed to be$result=mysql_query("SELECT * FROM members WHERE user='$myusername'");$result2=mysql_query("SELECT * FROM members WHERE email='$myemail2'");haha... it is always something so small Link to comment Share on other sites More sharing options...
MildewMan1 Posted May 13, 2007 Share Posted May 13, 2007 haha. good job. Figuring these d**ned things out can be so gratifying sometimes. Link to comment Share on other sites More sharing options...
astralaaron Posted May 13, 2007 Author Share Posted May 13, 2007 haha. good job. Figuring these d**ned things out can be so gratifying sometimes.yeah you got that right! thanks for working with me on that though! Link to comment Share on other sites More sharing options...
MildewMan1 Posted May 13, 2007 Share Posted May 13, 2007 you left your password (maybe it's a fake) in one of your codes above. and np, I get frustrated by this stuff too. Still learning it like you! Link to comment Share on other sites More sharing options...
astralaaron Posted May 13, 2007 Author Share Posted May 13, 2007 you left your password (maybe it's a fake) in one of your codes above. and np, I get frustrated by this stuff too. Still learning it like you! yeah thats just a temporary password, the page is on my local machine right now, it will be different once online! Link to comment Share on other sites More sharing options...
astralaaron Posted May 13, 2007 Author Share Posted May 13, 2007 edited it out anyway, thanks :-) Link to comment Share on other sites More sharing options...
MildewMan1 Posted May 13, 2007 Share Posted May 13, 2007 anytime Link to comment Share on other sites More sharing options...
justsomeguy Posted May 14, 2007 Share Posted May 14, 2007 Just to point this out, you probably could have solved this a lot quicker if you were displaying error messages. The queries were causing an error but were not showing the messages. If a query is failing, the first thing you should do (before you post a message anywhere) is checking appropriate error messages. mysql_error would have told you that the query is failing. Link to comment Share on other sites More sharing options...
astralaaron Posted May 14, 2007 Author Share Posted May 14, 2007 Just to point this out, you probably could have solved this a lot quicker if you were displaying error messages. The queries were causing an error but were not showing the messages. If a query is failing, the first thing you should do (before you post a message anywhere) is checking appropriate error messages. mysql_error would have told you that the query is failing.thanks, I forgot all about that! Link to comment Share on other sites More sharing options...
justsomeguy Posted May 14, 2007 Share Posted May 14, 2007 That amazes me, what do you guys do when you have errors? Do you just sit there and guess until you get it right? Or post a message on here and let other people figure it out? Wouldn't it be logical to just determine what the problem is and fix it? The only question usually is how to figure out what the problem is, if you have to look at an error log, or check a variable or function (as in this case), or check whatever. But step #1 in every single debugging situation is identify the problem, and to do that you need the error message. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.