Results 1 to 2 of 2

Thread: Another Variable Question

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Resolved Another Variable Question

    When a user updates their contact details I save the changes but get an "unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING" error when using the below code.

    PHP Code:
    $field_str .= "firstname = '$_POST['firstname']', ";
    $field_str .= "lastname = '$_POST['lastname']' "
    How can I get the above to work without having to declare the variables like in the below example?
    PHP Code:
    //eg.
    $firstname $_POST['firstname'];
    $lastname $_POST['lastname'];

    $field_str .= "firstname = '$firstname', ";
    $field_str .= "lastname = '$lastname' "

    EDIT: Got it working
    PHP Code:
    $field_str .= "firstname = '$_POST[firstname]', ";
    $field_str .= "lastname = '$_POST[lastname]', "
    Last edited by lintz; Feb 23rd, 2005 at 12:41 AM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Another Variable Question

    Quote Originally Posted by lintz
    EDIT: Got it working
    PHP Code:
    $field_str .= "firstname = '$_POST[firstname]', ";
    $field_str .= "lastname = '$_POST[lastname]', "
    Its alot better to use this method, then PHP doesn't have to work out whether the index you have used is a constant or a string. I.e: less resources are used.
    PHP Code:
    $field_str .= "firstname = '{$_POST['firstname']}', ";
    $field_str .= "lastname = '{$_POST['lastname']}', "
    P.s: are you checking that you post data has been escaped. What if someone puts a username in lile " ' OR 1 "??
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width