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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    716
    Thanks
    8
    Thanked 17 Times in 16 Posts

    If blank then dont Update

    How do I do it so when this page gets run by itself it doesn't update the table, since if it does it will just make all the fields blank.

    PHP Code:
    <?php
    require_once ('inc/config.php');
    $firstname mysql_real_escape_string ($_POST['firstname']);
    $lastname mysql_real_escape_string ($_POST['lastname']);
    $middlenamemysql_real_escape_string ($_POST['middlename']);
    $id 2;  
    $sql mysql_query ("
       UPDATE `testing` SET 
          `FirstName` = '"
    .$firstname."', 
          `LastName` = '"
    .$lastname."',
          `MiddleName` = '"
    .$middlename."' 
       WHERE `id` = '"
    .$id."'
    "
    )
    OR die (
    mysql_error());
    ?>
    Instead make it update the table only when the form updates it?

  • #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
    Check to see if $_POST is set, or is an array, and additionally, a popular method is to check the SUBMIT button's $_POST index to see if it's set and even if the value of it equals the submit button value on the html form.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Yes, check a particular value. I always go for the submission button. You can also check for the request method, though that does not guarentee that the values will be set.
    _POST is however always available regardless of if it is a posted form, and will always be an array, so you cannot check for isset on post, or if is_array, though you can check for !empty. I'm fairly certain about this, I remember a previous CLI run on phpinfo(INFO_VARIABLES); pulled up an empty array from post. Everything actually, except for sessions.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #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
    _POST is however always available regardless of if it is a posted form, and will always be an array, so you cannot check for isset on post, or if is_array
    Crap you're absolutely right...


  •  

    Posting Permissions

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