[RESOLVED] Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING
Results 1 to 4 of 4

Thread: [RESOLVED] Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    15

    resolved [RESOLVED] Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING

    Here is the full error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 13

    Line 13 States:
    PHP Code:
    $search mysql_query("SELECT * FROM searchengine WHERE pageurl = '$_POST['url']'"); 
    The code is for a search engine to check if the url exists and if it dosen't add it to the data base

    The whole code is
    PHP Code:
    <?php
    $mysql_host 
    "host";
    $mysql_database "database";
    $mysql_user "user";
    $mysql_password "pass";


    mysql_connect($mysql_host$mysql_user$mysql_password) or die(mysql_error()); 
    mysql_select_db($mysql_database) or die("ERROR"); 

    $pagedata htmlspecialchars(file_get_contents($_POST['url']));
    $pagedata str_replace("'","",$pagedata);
    $search mysql_query("SELECT * FROM searchengine WHERE pageurl = $_POST['url']"); // Here we select the rows with the id of 1
    while($row mysql_fetch_array($search)){ // We loop through the data

    if($_POST['url'] == $row['pageurl']){ // Check if the id exists in the table

    echo " IT DOES!!!"// yes it does

    }
    else
    {

    echo 
    " The url doesnt exist adding it"//else 




    mysql_query("INSERT INTO searchengine VALUES ('','$_POST[url]','$pagedata')");
    echo 
    "URL Added.<br><a href='./addurl.php'>Continue...</a>";
    }
    }
    ?>


    Thanks!

    Chase
    Last edited by chaseab; 05-20-2009 at 05:29 PM.

  2. #2
    Senior Member
    Join Date
    May 2009
    Posts
    165
    add a line before the line that says

    PHP Code:
    $search mysql_query("SELECT * FROM searchengine WHERE pageurl = '$_POST['url']'"); 
    That says

    PHP Code:
     $url $_POST['url']; 
    then use '$url' in place of $_POST['url'] (in the line that gives you the error)

    dno why this error happens, but i just tested it in my code and get the same error until i do that.

    Hope this helps,
    Paul

  3. #3
    Senior Member dagon's Avatar
    Join Date
    Nov 2001
    Posts
    6,178
    this one like the last can also be fixed by referring to the string section of the manual, look specificity at the A banana is example

  4. #4
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,429
    Also note that your code is vulnerable to SQL injection attacks. User-supplied data should never be placed directly into a SQL query string. Instead, it must first be sanitized with a function such as mysql_real_escape_string().

    EDIT: Also note that there is a more efficient (and cleaner) way of doing what you're trying to do. Since you don't want duplicate rows for the same URL, you should add a UNIQUE key on the 'url' column.

    That way, you'd simply perform an INSERT (without first SELECT'ing to test for a pre-existing row); if the INSERT query fails with error code 1062 (duplicate entry for a key), then you know that the URL already existed.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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