Jump to content

[SOLVED] form help


ohdang888

Recommended Posts

i'm making a form where people can sign-up to be a member. their info autmatically goes into a database.

 

i am now getting this error:

 

Parse error: syntax error, unexpected '"', expecting ']' in C:\xampp\htdocs\sign_up.php on line 19

 

that's the first problem, but i had a problem earlier where it was connecting to the table, but it wasn;t inserting the info, it was creating blank lines, so i messed with it a bit and now i have that problem...

 

Any ideas?

 

Thanks!

 

this is my code:

<?php 
mysql_connect("localhost", "----", "----") or die(mysql_error());
mysql_select_db("members") or die(mysql_error());

if($_POST['submit']){

	$_POST['username'] = trim($_POST['username']);
	if($_POST['username'] && strlen($_POST['username']) >= 3){
		$query = mysql_query("SELECT `id` FROM `user` WHERE `username`='".$_POST['username']."' LIMIT 1");
		if(mysql_num_rows($query)){
			$error['userexists'] = 'Username exists';
		}
	} else {
		$error['usernameinput'] = 'Please enter a username';
	}

			$_POST['username'] = trim($_POST['username']);
	if($_POST['email'] && strlen($_POST['email]) >= 5){
		$query = mysql_query("SELECT `id` FROM `user` WHERE `email`='".$_POST['email']."' LIMIT 1");//////////////[b]LINE 19[/b]
		if(mysql_num_rows($query)){
			$error['emailexists'] = 'Email is already signed up!';
		}
	} else {
		$error['emailinput'] = 'Please enter a valid e-mail';
	}


	$_POST['email'] = trim($_POST['email']);
	if($_POST['email']){
		 if(!eregi("^[a-zA-Z0-9]+[a-zA-Z0-9_.-]*@[a-zA-Z0-9]+[a-zA-Z0-9_.-])*\.[a-z]{2,4}$", $_POST['email'])){
		  $error['emailerror'] = 'Email Incorrect';
	  }
	} else {
		$error['emailinput'] = 'Please supply an email address';
	}

	if($_POST['password1'] && $_POST['password2']){
		if($_POST['password1'] != $_POST['password2']){
			$error['passmismatch'] = 'Passwords don\'t match';
		}
	} else {
		$error['passwordinput'] = 'Please enter your password in both fields';
	}
}

if(!$error && $_POST['submit']){

} else {

  $username = $_POST["username"];
  $email = $_POST["email"];
  $password = $_POST["password1"];
  
  $sql="INSERT INTO `user` (`username`, `password`, `email`) VALUES ( '$username', '$password', '$email')";
  
  mysql_query($sql) or die ( mysql_error());
  }	
?>

<html>
<form name=”reg” method=”post” >
username: <input type=”text” name=”username” /><br /><?php echo $error[’userexists’]; echo $error[’usernameinput’]; ?>
email: <input type=”text” name=”email” /><br />
password1: <input type=”password” name=”password1” /><br/>
password2: <input type=”password” name=”password2” /><br/>
<input type=submit name=”submit” value=”submit” /><br> 
</form>

Link to comment
Share on other sites

First Problem is on line 19 you have a " or ' the code is not liking.

instead of:

`username`='".$_POST['username']."'

Try using:

`username`='$_POST[username]'

instead.

 

As for your blank entries, it should only be a typo in one of your vairables, echo your vairables and c if they actually have a value

Link to comment
Share on other sites

if($_POST['email'] && strlen($_POST['email]) >= 5){

You're missing a closing quote there, also further down you have...

$error['passmismatch'] = 'Passwords don't match';

That should either be

$error['passmismatch'] = 'Passwords don\'t match';
#or
$error['passmismatch'] = "Passwords don't match";

Link to comment
Share on other sites

if($_POST['email'] && strlen($_POST['email]) >= 5){

You're missing a closing quote there, also further down you have...

$error['passmismatch'] = 'Passwords don't match';

That should either be

$error['passmismatch'] = 'Passwords don\'t match';
#or
$error['passmismatch'] = "Passwords don't match";

 

Yup, well spotted I always miss those 1s 2 :)

if($_POST['email'] && strlen($_POST['email]) >= 5){

should be..

if($_POST['email'] && strlen($_POST['email']) >= 5){

 

Link to comment
Share on other sites

Try changing:

 

$query = mysql_query("SELECT `id` FROM `user` WHERE `username`='".$_POST['username']."' LIMIT 1");

 

to:

 

$query = mysql_query("SELECT id FROM user WHERE username ='$_POST['username']' LIMIT 1");

 

and the other one:

 

$query = mysql_query("SELECT `id` FROM `user` WHERE `email`='".$_POST['email']."' LIMIT 1");

 

to

 

$query = mysql_query("SELECT id FROM user WHERE email='$_POST['email']' LIMIT 1");

Link to comment
Share on other sites

so how exactly will echo work...

 

i know all about echo and all that....

but when i click "submit" and the page refreshes, its not showing up anything

 

 $username = $_POST["username"];
 $email = $_POST["email"];
 $password = $_POST["password1"];
 
 echo $username;
 echo $email;
 echo $password;

 

 

 

Link to comment
Share on other sites

That will just break his queries

 

Try changing:

 

$query = mysql_query("SELECT `id` FROM `user` WHERE `username`='".$_POST['username']."' LIMIT 1");

 

to:

 

$query = mysql_query("SELECT id FROM user WHERE username ='$_POST['username']' LIMIT 1");

 

and the other one:

 

$query = mysql_query("SELECT `id` FROM `user` WHERE `email`='".$_POST['email']."' LIMIT 1");

 

to

 

$query = mysql_query("SELECT id FROM user WHERE email='$_POST['email']' LIMIT 1");

Link to comment
Share on other sites

so how exactly will echo work...

 

i know all about echo and all that....

but when i click "submit" and the page refreshes, its not showing up anything

 

  $username = $_POST["username"];
  $email = $_POST["email"];
  $password = $_POST["password1"];
  
  echo $username;
  echo $email;
  echo $password;

 

Change to

$_POST['username']; and the same with the other ones, ' ' quotes needs to be used with Form values.

Link to comment
Share on other sites

now its not even creating blank rows.... its doing nothing,..... AHHHH

if(!$error && $_POST['submit']){    ////// AM I SUPPOSED TO HAVE THE BELOW CODE RIGHT HERE????

} else {

  $username = $_POST['username'];
  $email = $_POST['email'];
  $password = $_POST['password1'];
  
  echo $username;
  echo $email;
  echo $password;
  echo '<br>';
   echo 'HEY HEY HEY';
    echo '<br>';
 echo '<br>';
  echo '<br>';
   echo '<br>';
    echo '<br>';
  
  
  $sql="INSERT INTO `user` (`username`, `password`, `email`) VALUES ( '$username', '$password', '$email')";
  
  mysql_query($sql) or die ( mysql_error());
  }
  }

 

the hey hey hey isn;'t hsowing up after i click submit

Link to comment
Share on other sites

now its not even creating blank rows.... its doing nothing,..... AHHHH

if(!$error && $_POST['submit']){    ////// AM I SUPPOSED TO HAVE THE BELOW CODE RIGHT HERE????

} else {

  $username = $_POST['username'];
  $email = $_POST['email'];
  $password = $_POST['password1'];
  
  echo $username;
  echo $email;
  echo $password;
  echo '<br>';
   echo 'HEY HEY HEY';
    echo '<br>';
 echo '<br>';
  echo '<br>';
   echo '<br>';
    echo '<br>';
  
  
  $sql="INSERT INTO `user` (`username`, `password`, `email`) VALUES ( '$username', '$password', '$email')";
  
  mysql_query($sql) or die ( mysql_error());
  }
  }

 

the hey hey hey isn;'t hsowing up after i click submit

 

Echo using "" and anything that need quotes inside of an echo use ' ' quotes;

 

P.S. don't need to quote at all if it is just a variable.

Link to comment
Share on other sites

I've done a bit of cleanup for you due to boredom, its not perfect (or tested) but I hope it will be helpful.

<?php 
mysql_connect("localhost", "", "") or die(mysql_error());
mysql_select_db("members") or die(mysql_error());
$aError     = array();
function basic_xss_clean($s)
{
    $s = trim(strip_tags(mysql_real_escape_string($s)));
    return $s;
}
if (isset($_POST['submit'])) {
	$bHasErrors = false;
                
	$_POST['username'] = trim($_POST['username']);

                if ($_POST['username'] && strlen($_POST['username']) >= 3) {
		$query = mysql_query("SELECT id FROM user WHERE username='".$_POST['username']."' LIMIT 1");
		if(mysql_num_rows($query)){
			$aError['userexists'] = 'Username exists';
		}
	} else {
		$aError['usernameinput'] = 'Please enter a username';
                        $bHasErrors = true;
	}

	$_POST['username'] = trim($_POST['username']);

                if ($_POST['email'] && strlen($_POST['email']) >= 5) {
		$query = mysql_query("SELECT id FROM user WHERE email='".$_POST['email']."' LIMIT 1");//////////////[b]LINE 19[/b]
		if (mysql_num_rows($query)){
			$aError['emailexists'] = 'Email is already signed up!';
		}
	} else {
		$aError['emailinput'] = 'Please enter a valid e-mail';
                        $bHasErrors = true;
	}


	$_POST['email'] = trim($_POST['email']);
	if ($_POST['email']) {
		 if(!eregi("^[a-zA-Z0-9]+[a-zA-Z0-9_.-]*@[a-zA-Z0-9]+[a-zA-Z0-9_.-])*\.[a-z]{2,4}$", $_POST['email'])){
		  $aError['emailerror'] = 'Email Incorrect';
	  }
	} else {
		$aError['emailinput'] = 'Please supply an email address';
                        $bHasErrors = true;
	}

	if ($_POST['password1'] && $_POST['password2']) {
		if ($_POST['password1'] != $_POST['password2']) {
		    $aError['passmismatch'] = "Passwords don't match";
		}
	} else {
	    $aError['passwordinput'] = 'Please enter your password in both fields';
                    $bHasErrors = true;
	}


if ($bHasErrors == true) {
            //dump errors on screen in untidy fashion
            print_r($aError);
            
}
        else {
            //consider moving these variable assignments along with some trim()'ing and strip_tags()'ing to the top and testing
            //those variables, it'll make things easier to work with
            $username = basic_xss_clean($_POST["username"]);
            $email    = basic_xss_clean($_POST["email"]);
            $password = basic_xss_clean($_POST["password1"]); 
  
            $sql="INSERT INTO user (username, password, email) VALUES ( '$username', '$password', '$email')";
            //echo $sql;
            mysql_query($sql) or die ( mysql_error());
        }
    }
?>

<html>
<form name="reg" method="post" >
username: <input type="text" name="username" /><span><?php if (isset($aError['userexists'])) echo $aError['userexists']; if (isset($aError['usernameinput'])) echo $aError['usernameinput']; ?></span><br />
email: <input type="text" name="email" /><br />
password1: <input type="password" name="password1" /><br/>
password2: <input type="password" name="password2" /><br/>
<input type=submit name="submit" value="submit" /><br> 
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.