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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post

    Multiple if variable =x update, updating all fields

    Hi,

    I have a checkbox form which is sent to my insert page, which looks like:
    Code:
    if ($_REQUEST['product1'] !=''){ 
    $sql="UPDATE products SET product1 ='requested' 
    WHERE client='{$_SESSION['client']}'";
    			
    mysql_query($sql,$con) or die(mysql_error());}
    
    if ($_REQUEST['product2'] !=''){ 
    $sql="UPDATE products SET product2 ='requested' 
    WHERE client='{$_SESSION['client']}'";
    			
    mysql_query($sql,$con) or die(mysql_error());}
    
    if ($_REQUEST['product3'] !=''){ 
    $sql="UPDATE products SET product3 ='requested' 
    WHERE client='{$_SESSION['client']}'";
    			
    mysql_query($sql,$con) or die(mysql_error());}
    But if only product2 is selected, all three still update as requested. I have no idea what is going wrong.

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,957
    Thanks
    9
    Thanked 727 Times in 721 Posts
    Hard to tell from that code what the issue might be.

    A starting point might be to point your form at this code:

    PHP Code:
    <?php
    // ------------------------------------
    print '$_POST array';
    // ------------------------------------
    print "<BR/>";
    // ------------------------------------
    foreach ( $_POST as $key => $value ) {
     print 
    $key " " "=" " " $value;
     print 
    "<BR/>";
    }
    // ------------------------------------
    print "<BR/>";
    // ------------------------------------
    print "<BR/>";
    // ------------------------------------
    print '$_GET array';
    // ------------------------------------
    print "<BR/>";
    // ------------------------------------
    foreach ( $_GET as $key => $value ) {
     print 
    $key " " "=" " " $value;
     print 
    "<BR/>";
    }
    // ------------------------------------
    print "<BR/>";
    // ------------------------------------
    print "<BR/>";
    // ------------------------------------
    print '$_REQUEST array';
    // ------------------------------------
    print "<BR/>";
    // ------------------------------------
    foreach ( $_REQUEST as $key => $value ) {
     print 
    $key " " "=" " " $value;
     print 
    "<BR/>";
    }
    // ------------------------------------
    ?>
    which will print out all the data sent by the form. From this you should be able to establish what the values of all your variables are, and hence identify the problem.

  • Users who have thanked SB65 for this post:

    Jenny Dithe (11-18-2010)

  • #3
    Regular Coder
    Join Date
    Sep 2010
    Posts
    460
    Thanks
    214
    Thanked 1 Time in 1 Post
    Thank you, managed to solve it, that got me on the right track.


  •  

    Posting Permissions

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