SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    wht's wrong with my code?

    PHP Code:
    foreach($_POST['100type'] AS $key=>$value) { // UPDATE 100 TYPE
        
    mysql_query("UPDATE order_details_table SET block_quantity='{$_POST['100quantity'][$key]}', block_pallets='{$_POST['100pallets'][$key]}', block_extras='{$_POST['100extras'][$key]}' WHERE order_id='$id'")
        or die(
    mysql_error()); 

    the above code updates table data. It does not give me any errors but it does not update the table data. It fills in zero instead of the number it should be.

    this code for checking post data
    PHP Code:
    echo '<pre style="text-align: left;">' print_r($_POSTtrue) . '</pre>'
    shows that the data is there, but it does not update the table. Here is the posted data:
    PHP Code:
    ...
    [
    100type] => Array
            (
                [
    1] => 10.01
                
    [2] => 10.02
                
    [3] => 10.03
                
    [4] => 10.04
                
    [5] => 10.31
                
    [6] => 10.83
                
    [7] => 10.702
                
    [8] => 10.772
                
    [9] => 10.71
                
    [10] => 10.72
                
    [11] => 10.73
                
    [12] => 10.74
            
    )

        [
    100perpallet] => Array
            (
                [
    1] => 180
                
    [2] => 240
                
    [3] => 360
                
    [4] => 576
                
    [5] => 144
                
    [6] => 288
                
    [7] => 280
                
    [8] => 560
                
    [9] => 360
                
    [10] => 480
                
    [11] => 720
                
    [12] => 1152
            
    )

        [
    100quantity] => Array
            (
                [
    1] => 654
                
    [2] => 458
                
    [3] => 0
                
    [4] => 0
                
    [5] => 0
                
    [6] => 0
                
    [7] => 0
                
    [8] => 0
                
    [9] => 0
                
    [10] => 0
                
    [11] => 0
                
    [12] => 0
            
    )
    ... 

  2. #2
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    One has to be able to inspect the evidence. Change
    PHP Code:
    mysql_query"UPDATE order_details_table SET block_quantity='{$_POST['100quantity'][$key]}', block_pallets='{$_POST['100pallets'][$key]}', block_extras='{$_POST['100extras'][$key]}' WHERE order_id='$id'") or die(mysql_error()); 
    to
    PHP Code:
    $sql "UPDATE order_details_table
               SET block_quantity = '
    {$_POST['100quantity'][$key]}',
                   block_pallets = '
    {$_POST['100pallets'][$key]}',
                   block_extras = '
    {$_POST['100extras'][$key]}'
             WHERE order_id = '
    $id'";
    echo 
    $sql;
    mysql_query($sql) or die(mysql_error()); 
    While this changes nothing, it lets you see the actual query sent to MySQL
    Denny Schlesinger
    web services

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,
    thanks for the reply.
    this is the sql statement that is echoed: UPDATE order_details_table SET block_quantity = '0', block_pallets = '0', block_extras = '0' WHERE order_id = '40'

    But the post data has :
    PHP Code:
     [100quantity] => Array
            (
                [
    1] => 654
                
    [2] => 458
                
    [3] => 0
                
    [4] => 0
                
    [5] => 0
                
    [6] => 0
                
    [7] => 0
                
    [8] => 0
                
    [9] => 0
                
    [10] => 0
                
    [11] => 0
                
    [12] => 0
            

    So block_quantity should be ='654'

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's the code again
    PHP Code:
    foreach($_POST['100type'] AS $key=>$value) {
    $sql "UPDATE order_details_table
               SET block_quantity = '
    {$_POST['100quantity'][$key]}',
                   block_pallets = '
    {$_POST['100pallets'][$key]}',
                   block_extras = '
    {$_POST['100extras'][$key]}'
             WHERE order_id = '
    $id'";}
    echo 
    $sql;
    mysql_query($sql) or die(mysql_error()); 

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No I am wrong.

    block_quantity is '0' cause its the last value in the array. the problem is that the actual table is not updated properly. All records get the last value of the post

  6. #6
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ROUBOS View Post
    No I am wrong.

    block_quantity is '0' cause its the last value in the array. the problem is that the actual table is not updated properly. All records get the last value of the post
    Why would one order have 12 sets of values? I'm not sure what you are doing but the foreach loop had a different purpose. Shouldn't each order have a single set of values?
    Denny Schlesinger
    web services

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2013
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now it works:
    here's the code
    PHP Code:
    foreach($_POST['100type'] AS $key=>$value) {
    $sql "UPDATE order_details_table
               SET block_quantity = '
    {$_POST['100quantity'][$key]}',
                   block_pallets = '
    {$_POST['100pallets'][$key]}',
                   block_extras = '
    {$_POST['100extras'][$key]}'
             WHERE order_id = '
    $id' AND block_type='{$_POST['100type'][$key]}'";
    echo 
    $sql;
    mysql_query($sql) or die(mysql_error()); 

    thanks for looking into this

  8. #8
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just to keep things neat and readable, and comment out the echo used for debugging...
    PHP Code:
    foreach($_POST['100type'] AS $key=>$value) {
    $sql "UPDATE order_details_table
               SET block_quantity = '
    {$_POST['100quantity'][$key]}',
                   block_pallets = '
    {$_POST['100pallets'][$key]}',
                   block_extras = '
    {$_POST['100extras'][$key]}'
             WHERE order_id = '
    $id'
               AND block_type='
    {$_POST['100type'][$key]}'";
    // echo $sql;
    mysql_query($sql) or die(mysql_error()); 

    thanks for looking into this
    My pleasure!
    Denny Schlesinger
    web services


Bookmarks

Posting Permissions

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