...

View Full Version : Error message: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),



dgunning
11-05-2012, 11:16 PM
I'm getting the above error message and I can't figure out what the problem is. Here's some of my code:



$db = mysql_connect("dgunning.db.8219830.hostedresource.com", "*****", "******");
mysql_select_db("dgunning", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
$sql = "SELECT op.name, op.stnum, op.direction, op.street, arch.architect, op.yearbuilt, op.url, op.id FROM op, arch
WHERE op.archno = arch.archno AND op.stnum = htmlspecialchars($_GET['stnum']) AND op.direction = htmlspecialchars($_GET['dir']) AND
op.street = htmlspecialchars($_GET['street']);"


I'm getting the error on the $sql= line. I'm pretty new to using php, so would really appreciate any help. thanks!

elhippie
11-05-2012, 11:49 PM
got it, read it on another form, hopefully it works

$db = mysql_connect("dgunning.db.8219830.hostedresource.com", "*****", "******");
mysql_select_db("dgunning", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
$sql = "SELECT op.name, op.stnum, op.direction, op.street, arch.architect, op.yearbuilt, op.url, op.id FROM op, arch
WHERE op.archno = arch.archno AND op.stnum = htmlspecialchars($_GET[stnum]) AND op.direction = htmlspecialchars($_GET[dir]) AND
op.street = htmlspecialchars($_GET[street]);"


the fix is with the ($_GET[]) functions, you gotta take away the ' ' around them

dgunning
11-05-2012, 11:57 PM
Thanks for the response. After making the change you suggest, I now get this error message:

Parse error: syntax error, unexpected '$result' (T_VARIABLE)

elhippie
11-06-2012, 12:05 AM
are you accessing another page using include (); cause its saying that $result is in the wrong spot. or your missing a ;, i'd have to see more code to help you

dgunning
11-06-2012, 12:14 AM
are you accessing another page using include (); cause its saying that $result is in the wrong spot. or your missing a ;, i'd have to see more code to help you

$result is in the next line of code, it's:



$result = safe_query($sql);


and here's safe query:



function safe_query ($query = "")
{
if (empty($query)) {return FALSE; }
$result = mysql_query($query)
or die("ack! query failed: "
."<li>errorno=".mysql_errno()
."<li>error=".mysql_error()
."<li>query=".$query
);
return $result;
}

elhippie
11-06-2012, 12:18 AM
$result is in the next line of code, it's:



$result = safe_query($sql);


and here's safe query:



function safe_query ($query = "")
{
if (empty($query)) {return FALSE; }
$result = mysql_query($query)
or die("ack! query failed: "
."<li>errorno=".mysql_errno()
."<li>error=".mysql_error()
."<li>query=".$query
);
return $result;
}



the error is here

$db = mysql_connect("dgunning.db.8219830.hostedresource.com", "*****", "******");
mysql_select_db("dgunning", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
$sql = "SELECT op.name, op.stnum, op.direction, op.street, arch.architect, op.yearbuilt, op.url, op.id FROM op, arch
WHERE op.archno = arch.archno AND op.stnum = htmlspecialchars($_GET['stnum']) AND op.direction = htmlspecialchars($_GET['dir']) AND
op.street = htmlspecialchars($_GET['street'])";
#HERE IS THE ERROR SWITCH THE ';' and the " around

dgunning
11-06-2012, 12:26 AM
Now I'm back to the original error message. Here's how my code stands now, this is from the beginning of this file.



include('basic.php');
// database connection stuff
$db = mysql_connect("dgunning.db.8219830.hostedresource.com", "*****", "*****");
mysql_select_db("dgunning", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");


$sql = "SELECT op.name, op.stnum, op.direction, op.street, arch.architect, op.yearbuilt, op.url, op.id FROM op, arch
WHERE op.archno = arch.archno AND op.stnum = htmlspecialchars($_GET['stnum']) AND op.direction = htmlspecialchars($_GET['dir']) AND
op.street = htmlspecialchars($_GET['street'])";

$result = safe_query($sql);


Thanks for your efforts, any other suggestions?

elhippie
11-06-2012, 12:32 AM
Now I'm back to the original error message. Here's how my code stands now, this is from the beginning of this file.



include('basic.php');
// database connection stuff
$db = mysql_connect("dgunning.db.8219830.hostedresource.com", "*****", "*****");
mysql_select_db("dgunning", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");


$sql = "SELECT op.name, op.stnum, op.direction, op.street, arch.architect, op.yearbuilt, op.url, op.id FROM op, arch
WHERE op.archno = arch.archno AND op.stnum = htmlspecialchars($_GET'stnum]) AND op.direction = htmlspecialchars($_GET[dir]) AND
op.street = htmlspecialchars($_GET[street])";

$result = safe_query($sql);


Thanks for your efforts, any other suggestions?


lol im srry i copied the first php code remove the ' from the $_GET functions




include('basic.php');
// database connection stuff
$db = mysql_connect("dgunning.db.8219830.hostedresource.com", "*****", "*****");
mysql_select_db("dgunning", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");


$sql = "SELECT op.name, op.stnum, op.direction, op.street, arch.architect, op.yearbuilt, op.url, op.id FROM op, arch
WHERE op.archno = arch.archno AND op.stnum = htmlspecialchars($_GET[stnum]) AND op.direction = htmlspecialchars($_GET[dir]) AND
op.street = htmlspecialchars($_GET[street])";

$result = safe_query($sql);

tangoforce
11-06-2012, 12:39 AM
$sql = "SELECT op.name, op.stnum, op.direction, op.street, arch.architect, op.yearbuilt, op.url, op.id FROM op, arch
WHERE op.archno = arch.archno AND op.stnum = htmlspecialchars($_GET['stnum']) AND op.direction = htmlspecialchars($_GET['dir']) AND
op.street = htmlspecialchars($_GET['street'])";


Should be:


$sql = "SELECT op.name, op.stnum, op.direction, op.street, arch.architect, op.yearbuilt, op.url, op.id FROM op, arch
WHERE op.archno = arch.archno AND op.stnum = '$_GET[stnum]' AND op.direction = '$_GET[dir]' AND
op.street = '$_GET[street]'";


Inside a "double quoted" string, you do not use single['quotes'] in your arrays. This will cause the error you have been complaining of. Also as far as I'm aware, mysql doesn't have that htmlspecialchars() function. In php again, inside your "double quoted" string, you cannot use a function. It IS a PHP function so you must use it in PHP and not inside a string:



$_GET['street'] = htmlspecialchars($_GET['street']);

dgunning
11-06-2012, 01:21 AM
That did it, the query is executing now. I have some additional issues later on in the code, but I'll see if I can get them working myself before asking for any additional help. Thanks a lot!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum