Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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!

  • #2
    New Coder
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the response. After making the change you suggest, I now get this error message:

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

  • #4
    New Coder
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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;


  • #6
    New Coder
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 

  • #7
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #8
    New Coder
    Join Date
    Mar 2012
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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); 

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,301
    Thanks
    57
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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']); 
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    dgunning (11-06-2012)

  • #10
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •