Jump to content


Photo

Easy Error, But cannot figure out!


  • Please log in to reply
13 replies to this topic

#1 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 08 August 2006 - 04:36 AM

I keep getting this error for my script that I just finished making:

Parse error: parse error, unexpected $ in /home/theblizz/public_html/studiocommunity/registration.php on line 81

here is my script:

<?

include('header.php');

function checkEmail($email) 
{
   if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) #checking to see if valid characters
   {
      return FALSE;
   }


if( (!$name) or (!$uname) or (!$pass) or (!$pass_two) or (!$email) )
	{
	echo('<center><h2>New User Registration</h2>
			<br>
			<form actoin="$php_self" method="post">
			<table border="0">
			<tr><td>Name:</td><td><input type="text" name="name" value="$name"></td></tr>
			<tr><td>Email:</td><td><input type="text" name="email" value="$email"></td></tr>
			<tr><td>Username:</td><td><input type="text" name="uname" value="$uname"></td></tr>
			<tr><td>Password:</td><td><input type="password" name="pass" value="$pass"></td></tr>
			<tr><td>Password:</td><td><input type="password" name="pass_two" value="$passTwo"></td></tr>
			'); }
			
if( (checkEmail($email) == TRUE) && ($pass == $passTwo) )
	{
	require_once('db_connect.php');
	$conn = db_connect();
	$db = mysql_select_db('theblizz_studio', $conn)
		or die ('Registration failure, try again.');
	$sql = 'SELECT * FROM users';
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
	$usertaken = $row['uname'];
	
	if( $uname == $usertaken ) 
		{
		echo('Username is already in use, please choose another<br>
				<a href="registration.php">Go Back</a>'); }
	else {
		$sql = 'INSERT INTO users
				(name, email, uname, pass) VALUES
				("$name", "$email", "$uname", "$pass")';
		$result = mysql_query($sql, $conn)
			or die ('Registration failure, try again.');
		
	if ( $result )
		{
		echo('Thanks, $name, you are now a member of the Studio Community!');
		}}}
		
else {
	if( $pass != $passTwo )
		{
		echo('<font color="red">*Your passwords did not match.</font>
			<br><br>
			<center><h2>New User Registration</h2>
			<br>
			<form actoin="$php_self" method="post">
			<table border="0">
			<tr><td>Name:</td><td><input type="text" name="name" value="$name"></td></tr>
			<tr><td>Email:</td><td><input type="text" name="email" value="$email"></td></tr>
			<tr><td>Username:</td><td><input type="text" name="uname" value="$uname"></td></tr>
			<tr><td>Password:</td><td><input type="password" name="pass" value="$pass"></td></tr>
			<tr><td>Password:</td><td><input type="password" name="pass_two" value="$passTwo"></td></tr>');
			}
	else {
		echo('<font color="red">*Your E-mail address was not valid.</font>
			<br><br>
			<center><h2>New User Registration</h2>
			<br>
			<form actoin="$php_self" method="post">
			<table border="0">
			<tr><td>Name:</td><td><input type="text" name="name" value="$name"></td></tr>
			<tr><td>Email:</td><td><input type="text" name="email" value="$email"></td></tr>
			<tr><td>Username:</td><td><input type="text" name="uname" value="$uname"></td></tr>
			<tr><td>Password:</td><td><input type="password" name="pass" value="$pass"></td></tr>
			<tr><td>Password:</td><td><input type="password" name="pass_two" value="$passTwo"></td></tr>');
			}}
?>


#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 08 August 2006 - 05:02 AM

for some reason the posts get all knocked out of whack when posting them.

Anyways, that error means that you did not close an if/else/elseif statemnet somewhere. Look through your code and see if you can find it.

Also a better way of using if/else/ifelse is like this.

if ($something == $something_else) {
    //do something
}elseif ($something == $whatever) {
    //do something else
}else{
   //do whatever
}

Hope this helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 05:08 AM

I dont know if its related or not... but
function checkEmail($email) 
{
   if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) #checking to see if valid characters
   {
      return FALSE;
   }

i think you mean

function checkEmail($email) 
{
   if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) #checking to see if valid characters
   {
      return FALSE;
   }
}

Why doesn't anyone ever say hi, hey, or whad up world?

#4 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 08 August 2006 - 05:23 AM

Thank you, that worked! But now I cannot figure out why the email check is not working, im not getting an error anymore, but it is saying that my email is not valid right off the bat, and its showing 2 forms.

#5 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 05:47 AM

Uhhh the function wont return true no matter what in its current state....

try

function checkEmail($email)
{
  if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) #checking to see if valid characters
  {
      return FALSE;
  }
else {
return TRUE;
}
}

Why doesn't anyone ever say hi, hey, or whad up world?

#6 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 08 August 2006 - 05:49 AM

hmmm, no im still getting the same thing.

here is the link so you can see:

http://theblizz.org/...egistration.php

#7 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 05:54 AM

Something is wrong with your eregi thing i think... I just tested it my self a little... try

function checkEmail($email) 
{
   if(!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $email))
   {
		return FALSE;
   }
	else { 
		return TRUE;
	}
}

Why doesn't anyone ever say hi, hey, or whad up world?

#8 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 05:57 AM

Oh and you realize your form is messed up right?
$var = "bob";
echo('hello "$var"');

would out put hello "$var"

I normally use echo "hello" . $var;
Why doesn't anyone ever say hi, hey, or whad up world?

#9 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 08 August 2006 - 06:01 AM

Ah, thank you for the hint.

But im still getting the email error.

#10 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 06:01 AM

Just a sec... I'll rewrite your script... lol
Why doesn't anyone ever say hi, hey, or whad up world?

#11 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 08 August 2006 - 06:10 AM

haha, well thank you!

#12 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 07:02 AM

Hehe sorry  I got a lil side tracked... Anyways here it is...

<?
include('header.php');
include('db_connect.php');
$conn = db_connect();
$db = mysql_select_db('dev', $conn) or die ('Database error.  Please try again later.');
function checkEmail($e) 
{
   if(!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $e))
   {
		return FALSE;
   }
	else { 
		return TRUE;
	}
}


$sub = $_POST['sub'];
if($sub) {
	if($_POST['name']) 
		{
			$name = $_POST['name']; 
		} else { $error .= "Please enter a user name.<BR>"; }
	if($_POST['email']) 
		{
			$email = $_POST['email'];
			if(checkEmail($email) != TRUE) { $error .= "Your Email Address is not valid.<BR>"; }
		} else { $error .= "Please enter an email address.<BR>"; }
	if($_POST['uname'])
		{
			$uname = $_POST['uname'];
			$q = "SELECT * from `users` WHERE `uname` = '" . $uname . "'";
			@$num = mysql_num_rows($q);
			if($num > 0) { $error .= "Sorry the user name you requested is not available.<BR>"; }	
		} else { $error .= "Please enter a username<BR>"; }
	if($_POST['pass']) 
		{ $pass = $_POST['pass']; } else { $error .= "Please enter a password<BR>"; }
	if($_POST['pass_two'])
	{ $pass_two = $_POST['pass_two']; } else { if($pass) {  $error .= "You did not enter your password a second time!<BR>"; } }
	
	
	if(($pass) && ($pass_two) && ($pass != $pass_two)) { $error .= "Your passwords do not match!<BR>"; }

if(!$error) {
	$sql = "INSERT INTO `users` (`name`, `email`, `uname`, `pass`) VALUES ('" . $name . "', '" . $email . "', '" . $uname . "', '" . $pass . "')";
	if(!mysql_query($sql, $conn)) { echo "Sorry! A database error has occured... Please try again later."; }
	else { $no_display = "yes"; ?> <meta http-equiv="refresh" content="0;url=<? echo $_SERVER['HTTP_SELF'] . "?success=yes&user=" . $uname; ?>"> <? }
}
}
if($no_display != "yes")
{
?>
			<center><font color="red"><? if($error) { echo "<B>One or more errors occured:</b> <BR>" . $error; }?></font>
			<h2>New User Registration</h2>
			<br>
<?
}

		
if(($_GET['success'] != "yes") && ($no_display != "yes")) { ?>
			<form action="" method="post">
			<table border="0">
			<tr><td>Name:</td><td><input type="text" name="name" value="<?=$name;?>"></td></tr>
			<tr><td>Email:</td><td><input type="text" name="email" value="<?=$email;?>"></td></tr>
			<tr><td>Username:</td><td><input type="text" name="uname" value="<?=$uname;?>"></td></tr>
			<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
			<tr><td>Password:</td><td><input type="password" name="pass_two""></td></tr>
			<tr><td><input type="submit" name="sub" value="Submit"></td></tr>
			</form>
<? }
else { echo "Thanks, " . $_GET['user'] . ", your are now a member of the Studio Community!"; }
if($conn)
{
mysql_close($conn);
}
?>

If I were you I would limit the lengths of the names usernames emails and passwords...  Also i would store the passwords in MD5...  This script does work though :D

(working copy up at the momment at http://corbin-dev.no-ip.org/reg/)
Why doesn't anyone ever say hi, hey, or whad up world?

#13 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 08 August 2006 - 07:17 AM

Wow, thanks a lot!

Although when I copy the code and paste it into DW its like triple spaced?  :D

#14 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 07:29 AM

Hmmm I dont know whats causin that lol
Why doesn't anyone ever say hi, hey, or whad up world?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users