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 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts

    Make long statements on multiple lines?

    I have a long query and would like to put it on multiple lines.

    I would like to make this:
    PHP Code:
    WHERE id '%d'",mysql_real_escape_string($_SESSION["php_g_edit_employee_last_name"]),mysql_real_escape_string($_SESSION["php_g_edit_employee_first_name"]),mysql_real_escape_string($_SESSION["php_g_edit_employee_middle_name"]),mysql_real_escape_string($_SESSION["php_g_employee_cellular_provider"]),mysql_real_escape_string($php_employee_other_cellular_provider),mysql_real_escape_string($_SESSION["php_g_employee_cellular_phone"])); 
    into this:
    PHP Code:
    WHERE id '%d'",mysql_real_escape_string($_SESSION["php_g_edit_employee_last_name"]),
    mysql_real_escape_string($_SESSION["
    php_g_edit_employee_first_name"]),
    mysql_real_escape_string($_SESSION["
    php_g_edit_employee_middle_name"]),
    mysql_real_escape_string($_SESSION["
    php_g_employee_cellular_provider"]),
    mysql_real_escape_string($php_employee_other_cellular_provider),
    mysql_real_escape_string($_SESSION["
    php_g_employee_cellular_phone"])); 
    where it is more readable.

    Thanks...
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    What's your question?

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    In my editor, how can I make the multiple query lines? When I try to do it I get a syntax error on my query string. I tried adding a period after each line but I guess that doesn't work.

    I'd like the lines to LOOK something like this in my editor but the query string won't work if I do.

    PHP Code:
    WHERE id '%d'",mysql_real_escape_string($_SESSION["php_g_edit_employee_last_name"]),
    mysql_real_escape_string($_SESSION["
    php_g_edit_employee_first_name"]),
    mysql_real_escape_string($_SESSION["
    php_g_edit_employee_middle_name"]),
    mysql_real_escape_string($_SESSION["
    php_g_employee_cellular_provider"]),
    mysql_real_escape_string($php_employee_other_cellular_provider),
    mysql_real_escape_string($_SESSION["
    php_g_employee_cellular_phone"])); 
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    That can't be the entire piece of code; it's not valid the first way you have it. I can't really help if I can't see the entire statement.

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    301
    Thanks
    7
    Thanked 2 Times in 2 Posts
    What editor are you using?

    do you need spaces after the commas?
    I'm a little out of practice but I seem to recall it may have mattered to me once.

    The whole statement would be helpful.

  • #6
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Can't you just hit Enter and Tab to make long query lines more readable? I use Gedit and am 90% sure it will be OK.


    ---------------------
    Leonard Whistler

  • #7
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    No, entering new line and then tab does not work. I'm using EditPLus2 editor.

    Here is the whole code structure of what I'd like to be able to do on multiple lines and not get this kind of error:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

    This example isn't too bad but I have some updates that contain a lot of fields so I have a lot of mysql_real_escape_string() lines and I'd just like to "see" them each on one line in my editor.

    PHP Code:
    $php_SQL sprintf("UPDATE Employees SET last_name = '%s'"
    ", first_name = '%s'"
    ", middle_name = '%s'"
    " WHERE id = '%d'"
    ,
    mysql_real_escape_string("Smith"),
    mysql_real_escape_string("John"),
    mysql_real_escape_string("J"),
    mysql_real_escape_string(5)); 
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #8
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    I just got it to work by opening up the database before executing the sprintf() function. Entering enter and tab does work now. I would never have guessed that the database had to be open prior to using sprintf().
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #9
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    $php_SQL = sprintf("UPDATE Employees SET last_name = '%s',
            first_name = '%s',
            middle_name = '%s',
            WHERE id = '%d',
            mysql_real_escape_string('Smith'),
            mysql_real_escape_string('John'),
            mysql_real_escape_string('J'),
            mysql_real_escape_string(5)");
    Last edited by MattF; 02-12-2010 at 01:40 AM.

  • #10
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Quote Originally Posted by rfresh View Post
    I would never have guessed that the database had to be open prior to using sprintf().
    The database connection was necessary because of your use of mysql_real_escape_string()
    John

  • #11
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Like I mentioned in your previous thread it would be more advantageous to use the mressf function for these long queries with multiple values you need to run mysql_real_escape_string on at once, and would make it far more readable
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

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