Jump to content

Help Please if you can :)


will_1990

Recommended Posts

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

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.