Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-05-2012, 11:16 PM   PM User | #1
dgunning
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
dgunning is an unknown quantity at this point
Error message: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),

I'm getting the above error message and I can't figure out what the problem is. Here's some of my code:

PHP 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!
dgunning is offline   Reply With Quote
Old 11-05-2012, 11:49 PM   PM User | #2
elhippie
New Coder

 
Join Date: Mar 2012
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
elhippie is an unknown quantity at this point
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
elhippie is offline   Reply With Quote
Old 11-05-2012, 11:57 PM   PM User | #3
dgunning
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
dgunning is an unknown quantity at this point
Thanks for the response. After making the change you suggest, I now get this error message:

Parse error: syntax error, unexpected '$result' (T_VARIABLE)
dgunning is offline   Reply With Quote
Old 11-06-2012, 12:05 AM   PM User | #4
elhippie
New Coder

 
Join Date: Mar 2012
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
elhippie is an unknown quantity at this point
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
elhippie is offline   Reply With Quote
Old 11-06-2012, 12:14 AM   PM User | #5
dgunning
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
dgunning is an unknown quantity at this point
Quote:
Originally Posted by elhippie View Post
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:

PHP Code:
$result safe_query($sql); 
and here's safe query:

PHP Code:
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;

dgunning is offline   Reply With Quote
Old 11-06-2012, 12:18 AM   PM User | #6
elhippie
New Coder

 
Join Date: Mar 2012
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
elhippie is an unknown quantity at this point
Quote:
Originally Posted by dgunning View Post
$result is in the next line of code, it's:

PHP Code:
$result safe_query($sql); 
and here's safe query:

PHP Code:
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
PHP 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'])"
;
 
#HERE IS THE ERROR SWITCH THE ';' and the " around 
elhippie is offline   Reply With Quote
Old 11-06-2012, 12:26 AM   PM User | #7
dgunning
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
dgunning is an unknown quantity at this point
Now I'm back to the original error message. Here's how my code stands now, this is from the beginning of this file.

PHP Code:
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?
dgunning is offline   Reply With Quote
Old 11-06-2012, 12:32 AM   PM User | #8
elhippie
New Coder

 
Join Date: Mar 2012
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
elhippie is an unknown quantity at this point
Quote:
Originally Posted by dgunning View Post
Now I'm back to the original error message. Here's how my code stands now, this is from the beginning of this file.

PHP Code:
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


PHP Code:
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); 
elhippie is offline   Reply With Quote
Old 11-06-2012, 12:39 AM   PM User | #9
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,513
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
PHP Code:
$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:
PHP Code:
$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:

PHP Code:
$_GET['street'] = htmlspecialchars($_GET['street']); 
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
dgunning (11-06-2012)
Old 11-06-2012, 01:21 AM   PM User | #10
dgunning
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
dgunning is an unknown quantity at this point
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!
dgunning is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:58 AM.


Advertisement
Log in to turn off these ads.