Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unexpected t constant encapsed string

Status
Not open for further replies.

verbatim1

Programmer
Apr 18, 2005
58
US
on line 14 below. what is it please?


<?

$ID = uniqid("userID");

$db = mysql_connect("localhost","xxxxx","xxxxx");

mysql_select_db (secretDB);

$result = mysql_query ("INSERT INTO users (id, real_name, username, password, email)
                VALUES ('$ID', '$real_name', '$username', '$userpass',
'$email')              ");
if(!$result)
{
   echo '<b>User not added:</b>' , mysql_error();
   exit;
}
if($result)
    {
    mysql_close($db);
    print "User <b>$username</b> added sucessfully!";
    }
else
{
print ("Wrong Password");
}
?>
 
think it should be

echo "<b>User not added:</b>".mysql_error();
 
i downloaded a php editor [PhpEdit] because i read it had a "debugger." I thought this meant it would suggest solutions to problems such as this one but it just points out what line the error is in. Any one know a editor that suggests solutions?


on another note, Steven290, i changed the single quotations back to double, [which they were originally]

i also changed the comma in front of mysql to a period.\

still no luck. Any more suggestions...




 
I cut and pasted your code into the editor I use (TopStyle Pro), it did not give an error.

The use of a comma and a period in the echo statement have the same end result.

Ken
 
thats strange that you get no error with your php editor.

here is the code after making the changes steven suggested:

<?

$ID = uniqid("userID");

$db = mysql_connect("localhost","test","test1");

mysql_select_db (secretDB);

$result = mysql_query ("INSERT INTO users (id, real_name, username, password, email)
VALUES ('$ID', '$real_name', '$username', '$userpass',
'$email') ");
if(!$result)
{
echo "<b>User not added:</b>" .mysql_error();
exit;
}
if($result)
{
mysql_close($db);
print "User <b>$username</b> added sucessfully!";
}
else
{
print ("Wrong Password");
}
?>
 
Nope, still no syntax error.

What is your line 14 and the surrounding lines.

Ken
 
line 14 is

echo "<b>User not added:</b>" .mysql_error();
 
Usually, when you get this error, the error will really be on a line prior to the line PHP is pointing at.

Look for unmatched quotes or curly braces "}".

PHP will continue to parse your script trying to figure out what you want until it gives up in frustration and then issue that error.

Try breaking your MySQL statements into many lines. Instead of
Code:
$result = mysql_query ("INSERT INTO users (id, real_name, username, password, email)
                VALUES ('$ID', '$real_name', '$username', '$userpass',
'$email')              ");
try
Code:
$query = "INSERT INTO users (id, real_name, username, password, email) VALUES ('$ID', '$real_name', '$username', '$userpass','$email')";
$result = @mysql_query($query) or die('Problem with query:' . $query .'<br>'.mysql_error());

Also, when you post your code, please put it between [ignore]
Code:
[/ignore]
tags. This will make it much easier to read.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top