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
https://forums.phpfreaks.com/topic/46255-unexpected-t_echo/
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
https://forums.phpfreaks.com/topic/46255-unexpected-t_echo/#findComment-224964
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
https://forums.phpfreaks.com/topic/46255-unexpected-t_echo/#findComment-224966
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
https://forums.phpfreaks.com/topic/46255-unexpected-t_echo/#findComment-225152
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
https://forums.phpfreaks.com/topic/46255-unexpected-t_echo/#findComment-225183
Share on other sites

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.