will_1990 Posted November 13, 2008 Share Posted November 13, 2008 I am trying to create a simple registration form and i want to confirm the email address and password. I have found a basic script to help confirm the password and have tried to edit it to confrim the email address. I am trying to use the method where the user has to enther the information twice and they have to match for it to continue. However, now i am getting no output on the page. I am very new to php so sorry if this is sounding very newbish! i will paste the code below, its not too long! Thanks for any help (or just pointing me in the right direction) in advance! <?php if($_POST) { $password = $_POST['password']; $confirm1 = $_POST['confirm1']; $email = $_POST['email']; $confirm2 = $_POST['confirm2']; if($password != $confirm1, $email != $confirm2) { ?> <span style='color:red'>Error: Passwords or email do not match!</span> <?php } else { $dbhost = 'stocks'; $dbuser = 'wbennett'; $dbpass = 'mysql5'; $dbname = 'wbennett'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $query = sprintf("SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER('%s')", mysql_real_escape_string($_POST['username'])); $result = mysql_query($query); list($count) = mysql_fetch_row($result); if($count >= 1) { ?> <span style='color:red'>Error: that username is taken.</span> <?php } else { $query = sprintf("INSERT INTO users(username,password, email_address) VALUES ('%s','%s');", mysql_real_escape_string($_POST['username']), mysql_real_escape_string(md5($password))), mysql_real_escape_string($_POST['email']); mysql_query($query); ?> <span style='color:green'>Congratulations, you registered successfully!</span> <?php } } } ?> <form method='post' action='register.php'>Username: <input type='text' name='username' /><br /> Password: <input type='password' name='password' /><br /> Confirm Password: <input type='password' name='confirm1' /><br /> Email: <input type='text' name='email' /><br> Confirm Email <input type='text' name='confirm2' /> <br> <input type='submit' value='Register!' /> </form> ps. as you can see i have created a few more variables to try a reconfirm it, i have probably gone about this the wrong way! I feel that once i have this sorted i can start adding the extra user input features! Link to comment https://forums.phpfreaks.com/topic/132617-help-please-if-you-can/ Share on other sites More sharing options...
revraz Posted November 13, 2008 Share Posted November 13, 2008 Try using || (or) in your IF statement instead of a comma. Link to comment https://forums.phpfreaks.com/topic/132617-help-please-if-you-can/#findComment-689588 Share on other sites More sharing options...
will_1990 Posted November 13, 2008 Author Share Posted November 13, 2008 thank you for your advice, neither || or the "or" command worked in place of the comma. I although if it had it would have only ensured one of the two checks was ok instead of both? Do you think "and" would work? thanks again! Will Link to comment https://forums.phpfreaks.com/topic/132617-help-please-if-you-can/#findComment-689595 Share on other sites More sharing options...
revraz Posted November 13, 2008 Share Posted November 13, 2008 Try it? thank you for your advice, neither || or the "or" command worked in place of the comma. I although if it had it would have only ensured one of the two checks was ok instead of both? Do you think "and" would work? thanks again! Will Link to comment https://forums.phpfreaks.com/topic/132617-help-please-if-you-can/#findComment-689597 Share on other sites More sharing options...
will_1990 Posted November 13, 2008 Author Share Posted November 13, 2008 nope still no output, nice try though. It can be so fustrating when things just dont do what i want! :-\ Link to comment https://forums.phpfreaks.com/topic/132617-help-please-if-you-can/#findComment-689604 Share on other sites More sharing options...
revraz Posted November 13, 2008 Share Posted November 13, 2008 So what is or isn't working. When you echo the variables, what do they contain? Do you always get the Error: Passwords or email do not match result? Link to comment https://forums.phpfreaks.com/topic/132617-help-please-if-you-can/#findComment-689678 Share on other sites More sharing options...
xtopolis Posted November 14, 2008 Share Posted November 14, 2008 You have so many errors in your syntax. Please use error reporting and it will tell you exactly what's wrong. Mainly, your use of commas, and improper (); For future reference, at the top of pages that aren't working, try: error_reporting(E_ALL); This should work, at least on the PHP side; <?php error_reporting(E_ALL); if($_POST) { $password = $_POST['password']; $confirm1 = $_POST['confirm1']; $email = $_POST['email']; $confirm2 = $_POST['confirm2']; if($password != $confirm1 || $email != $confirm2) { ?> <span style='color:red'>Error: Passwords or email do not match!</span> <?php } else { $dbhost = 'stocks'; $dbuser = 'wbennett'; $dbpass = 'mysql5'; $dbname = 'wbennett'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $query = sprintf("SELECT COUNT(id) FROM users WHERE UPPER(username) = UPPER('%s')"); mysql_real_escape_string($_POST['username']); $result = mysql_query($query); list($count) = mysql_fetch_row($result); if($count >= 1) { ?> <span style='color:red'>Error: that username is taken.</span> <?php } else { $query = sprintf("INSERT INTO users(username,password, email_address) VALUES ('%s','%s')"); mysql_real_escape_string($_POST['username']); mysql_real_escape_string(md5($password)); mysql_real_escape_string($_POST['email']); mysql_query($query); ?> <span style='color:green'>Congratulations, you registered successfully!</span> <?php } } } ?> <form method='post'>Username: <input type='text' name='username' /><br /> Password: <input type='password' name='password' /><br /> Confirm Password: <input type='password' name='confirm1' /><br /> Email: <input type='text' name='email' /><br> Confirm Email <input type='text' name='confirm2' /> <br> <input type='submit' value='Register!' /> </form> Link to comment https://forums.phpfreaks.com/topic/132617-help-please-if-you-can/#findComment-689917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.