inserting data into mysql database using php

后端 未结 7 647
生来不讨喜
生来不讨喜 2020-12-22 01:24

I have a php order form named (order.php) and when the user clicks the (submit button \"Next Step\") it takes him to another page called (confirm-order.php)

The (con

7条回答
  •  萌比男神i
    2020-12-22 01:34

    EDIT: a simple example

    do

    , validation and inserting in one file, say form.php:

     go insert!
    
            // I'll do the db-operation with PDO and a prepared statement.
            // this is cool, easy and safe. LEARN IT!
    
            $sql = "INSERT INTO table (item,price) VALUES (:item,:price)";
    
            $insert = $db->prepare($sql);
            $insert->execute(array(
                ':item' => $_POST['item'], 
                ':price' => $_POST['price']
                ));
        } // $error
     } // submit
    ?>
    

    Now, in the of the same page...

     confirm
    ?>
    

    Confirmed!

    Your data has been sent, thank you very much!

    go to somepage display form ?>

    Please enter data

    $msg) $output .= (strlen($output) > 0?', ':'') . "[$field]: $msg"; echo "

    There were errors: $output

    "; } // $error ?>

    item-name:

    price:

    See the use of a ternary-operator for setting the value-attribute of the -elements:

    (?:)
    

提交回复
热议问题