neverbegosu Posted December 20, 2010 Share Posted December 20, 2010 Hey fellas, and ladies, and all you other php wize's. Names mike and I'm new to php and mysql. Ive done alot of self study but have no formal training at all. I am pretty much just winging my code from w3 schools and other php online codeing helps. I am currently making a registration script for my site, and have hit a bit of a snag. Her is the current code for my regpass.php. <?php include('srvdbcon.php'); $NewUserNameTest=$_POST['NewUserName']; if(!ereg('[^A-Za-z0-9]',$NewUserNameTest)) { $query="SELECT * FROM user WHERE user ='$_POST(NewUserName)'"; $result=mysql_query($query); $num=mysql_num_rows($result); if($num == 0) { $query2="SELECT * FROM user WHERE email ='$_POST(NewUserEmail)'"; $result2=mysql_query($query2); $num2=mysql_num_rows($result2); if ($num2 == 0) { if(($_POST[NewUserPw]==$_POST[NewUserPwCon])&&($_POST[NewUserEmail]==$_POST[NewUserEmailCon])) { //Create a random code $confirm_code=md5(uniqid(rand())); //HACK PREVENTION $name=strip_tags($_POST['NewUserName']); $email=strip_tags($_POST['NewUserEmail']); $pw=strip_tags($_POST['NewUserPw']); //Insert Information Into Temp Code $sql="INSERT INTO temp SET code='$confirm_code',user='$name', email='$email', password='$pw'"; $result=mysql_query($sql); if($result) { $message="SCG.O Confirmation \r\n"; $message="Enter this confirmation code into confirmation page.\r\n"; $message="Enter code into confirmation: $confirm_code"; $sentmail=mail("$email",'Registration Confirmation',"$message",'From: SCGAdmin@uprisetechnology.com'); header("Location:index.php"); } else { die ("Something went wrong."); } } else { die("Password And / Or Email does not match the confirmation entry"); } } else { die("Email Already in Use"); } } else { die("Username already in use"); } } else { die("Username includes Bad Characters."); } ?> ---------------------------------------------------------------------------- The problem I am having is the code executes up to Confirming email and password with the confirming. I have checked, and double checked, the names of the variables $NewUserEmail $NewUserEmailCon $NewUserPw $NewUserPwCon When I click the register button it runs the regpass.php but I am getting the Die results for Error with matching confirmations. Any help would be appreciated. I know it is not the neatest codeing, nor is it probably logical to more vast programmers, but I am learning, and programming accourding to my own logic so I can understand it. Thanks. The code does not post anything to the mysql db but everything else is set up properly. The DB works, I have created this kind of script before with help from others, but this one is using my logic so I can understand the code. Thanks again. NeverBeGosu Quote Link to comment Share on other sites More sharing options...
neverbegosu Posted December 20, 2010 Author Share Posted December 20, 2010 Wow I know its the holidays but... someone has to have a few seconds to look over the code. Or did I miss something? Friends told me this is the place to go. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 20, 2010 Share Posted December 20, 2010 some of us have jobs. suggestion: always check the results of your SQL queries and view the SQL you are executing. $query="SELECT * FROM user WHERE user ='$_POST(NewUserName)'"; $result=mysql_query($query) or die(mysql_error() . " IN $query"); Quote Link to comment Share on other sites More sharing options...
The Letter E Posted December 20, 2010 Share Posted December 20, 2010 some of us have jobs. suggestion: always check the results of your SQL queries and view the SQL you are executing. $query="SELECT * FROM user WHERE user ='$_POST(NewUserName)'"; $result=mysql_query($query) or die(mysql_error() . " IN $query"); I agree with BlueSky on this. It is very important to check your requests. To add, it helps to echo out your variables while testing, and also don't forget to check your mail functions as well. Here's what I do when I have a query that is not working... 1. echo out your sql statement, so you can see what it looks like after php parses it 2. enter it into the SQL code window in your phpMyAdmin If it works in your phpMyAdmin chances are you are not escaping something or missing ' ' around a value. I wish I had time to put your code into production and test, but I don't right now. I will check on it later and if you are still hunting I will be happy to provide more help when time allows. Quote Link to comment Share on other sites More sharing options...
The Letter E Posted December 20, 2010 Share Posted December 20, 2010 Also try this: $sql="SELECT * FROM user WHERE user = '".$myVar."'"; That was just a basic change in your syntax. See if you notice the difference and can apply it to your script. Quote Link to comment Share on other sites More sharing options...
neverbegosu Posted December 20, 2010 Author Share Posted December 20, 2010 the code i provided for my posting to db works fine, I tested it on other script. Post fine to db. I just cant figure out where the error is before that. The code provided doesnt even reach the point of posting to sql. Its erroring at the confirmation email and password check, and I cant figure out why. Quote Link to comment Share on other sites More sharing options...
topcat Posted December 21, 2010 Share Posted December 21, 2010 Just before the line where you do the comparison add this code and run the script again: echo "NewUserPass: {$_POST['NewUserPw']} \n"; echo "NewUserPwCon: {$_POST['NewUserPwCon']} \n"; echo "NewUserEmail: {$_POST['NewUserEmail']} \n"; echo "NewUserEmailCon: {$_POST['NewUserEmailCon']} \n"; exit; That way you can see what's in the variables and make sure you're getting what you should be getting, if that is the place the script is failing then that's the best place to start looking Also, just noticed - you don't have single quotes around the names of the keys in your POST variables - I'm guessing that's just in the forum post but if it's in your code it will not be helping at all. HTH Quote Link to comment 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.