www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] Parse Error

  1. #1
    Join Date
    Nov 2007
    Posts
    53

    resolved [RESOLVED] Parse Error

    Can someone please help me this is hurting my head, I Cant figure this error out:

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/accordd1/public_html/artblock/regfix.php on line 72


    here is a piece of code:

    Code:
    if ( $query == true && $query0 == true)
    	{
    		mysql_query("INSERT INTO 'FREE USER' ('UserID', 'E-mail', 'Password', 'Region', 'Gender', 'AGE','Newsletter') 	   	
    		  VALUES
    		('0','$_POST['email']','$_POST['password']','$_POST['country']', '$_POST['gender']','$_POST['age']','$_POST['subscribe']')");
    	
    	}
    line 72:
    Code:
    ('0','$_POST['email']','$_POST['password']','$_POST['country']', '$_POST['gender']','$_POST['age']','$_POST['subscribe']')");
    your help will be greatly appreciated

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    Use curly brace "complex" notation for your array elements within the double-quoted string, or else use concatenation.
    PHP Code:
    // complex notation:
    $string "This is a {$array['sample']} string";
    // concatenation:
    $string "This is a " $array['sample'] . " string"
    The other alternative is to remove the quotes from around the array indexes, due to a quirk in the PHP parser. However, I prefer not to do that as it is a bad habit to get into. (See the section entitled "Why is $foo[bar] wrong?" on this page.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2007
    Posts
    53
    they werent meant to be array indexes, its a record into mysql adn query and query 0 are just 2 boolean vars i set earlier in the script
    Last edited by Pream; 05-22-2008 at 05:59 AM.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    $_POST is an array, and in $_POST['email'], 'email' is an index to that array.
    PHP Code:
    mysql_query("INSERT INTO 'FREE USER' ('UserID', 'E-mail', 'Password', 'Region', 'Gender', 'AGE','Newsletter')            
       VALUES ('0', '
    {$_POST['email']}', '{$_POST['password']}', '{$_POST['country']}', '{$_POST['gender']}', '{$_POST['age']}', '{$_POST['subscribe']}')"); 
    However, ultimately, this syntax problem is a minor issue compared to the fact that your code is wide open to SQL injection attacks. See www.php.net/mysql_real_escape_string for more info, as well as http://xkcd.com/327/.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Nov 2007
    Posts
    53
    thanks a lot

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
  •  
HTML5 Development Center



Recent Articles