Jump to content

Unexpected T_ECHO


Ames

Recommended Posts

Hi guys,

 

I'm new here and have just started learning to program. At the moment I am writing a simple login and registration script.

 

My problem is that I keep getting this message

 

Parse error: parse error, unexpected T_ECHO in C:\Program Files\xampp\htdocs\forum_new\register.php on line 33

 

Here is the script:

 

<?php 

include("config.php"); 

$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());


mysql_select_db($database)
or die ("Could not select database because ".mysql_error());


$check = "select id from $table where username = '".$_POST['username']."';"; 
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry); 

if ($num_rows != 0) 
{ 
	echo ("Sorry, there the username $username is already taken.<br>");
	echo ("<a href=register.html>Try again</a>");
	exit; 
} 

else 
{

	$insert = mysql_query("INSERT INTO $table (user_name, password, email) 
	VALUES ('" . $_POST["txtusername"] . "', '" . $_POST["txtpassword"] . "', '" . $_POST["txtemail"] . "')"


	or die ("Could not insert data because ".mysql_error())

	echo ("Your user account has been created!<br>"); // this is the line reported as error

	echo ("Now you can <a href=login.html>log in</a>"); 
}

?>

 

The line in question is in bold. I have tried everything, removing the brackets, quotes, semi colon, adding a semi colon at the end of the above line. Nothing seems to work.

 

I would be very greatful if you guys could provide any help.

Thanks in advance.

 

 

Link to comment
Share on other sites

I have tried what you said but now I get this error

 

Parse error: parse error, unexpected ';' in C:\Program Files\xampp\htdocs\forum_new\register.php on line 31

 

This relates to the die statement, the semi colon which I just added.

 

 

Link to comment
Share on other sites

You're also missing a parenthesis.

 

$insert = mysql_query("INSERT INTO $table (user_name, password, email)

      VALUES ('" . $_POST["txtusername"] . "', '" . $_POST["txtpassword"] . "', '" . $_POST["txtemail"] . "')")

     

     

      or die ("Could not insert data because ".mysql_error());

 

Link to comment
Share on other sites

I should also mention you never want to insert POST or GET data directly into your database.  At a minimum you should wrap them in mysql_real_escape_string...

 

mysql_query("INSERT INTO $table (user_name, password, email)

      VALUES ('" . mysql_real_escape_string($_POST["txtusername"]) . "', '" . mysql_real_escape_string($_POST["txtpassword"]) . "', '" . mysql_real_escape_string($_POST["txtemail"]) . "')")

 

But you should probably do some data validation first (like no spaces in passwords, valid chars in username, etc.)  So check POST and GET for security and data validation.

Link to comment
Share on other sites

Well i thought the problem was solved, but I was wrong. I have tried all of the suggestions that you guys have kindly given me but no matter what I do the same error keeps turning up.

 

Parse error: parse error, unexpected ';' in C:\Program Files\xampp\htdocs\forum_new\register.php on line 31

 

Which relates to the semi colon added after the die statement. If I remove this then I get this error:

 

Parse error: parse error, unexpected T_ECHO in C:\Program Files\xampp\htdocs\forum_new\register.php on line 33

 

As you can see by removing the semi colon there is no problem with the "die" line. However I know that it is needed.

I have also tried everything I can think of to try and fix the T_ECHO but with no luck.

 

If anyone can help it will be really appreciated.

Link to comment
Share on other sites

Your statement above the echo should look like

 

$insert = mysql_query(...) or die(...);

 

The die isn't an independent statement in this case.  And at one point your mysql_query() call was missing the right parenthesis.  If all of the parens are closed and the semicolon is there you still get an error?  Because the only other possible syntax problem would be quoting, but those look OK.

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.