简体   繁体   中英

Insert/post the contents of a table data into a database

please i need to insert the value of a table data into the database using a post submit but i dont seem to get it right... The code isn't complete, all i just need is for anyone to put me through the post submit data.

    <?php 
    if(isset($_POST['submit'])){
        $title        = $_POST[$product['title']];
        $slug         = $_POST[$product['slug']];
        $slug         = $_POST[$product['description']];
        $quantity     = $_POST[$product['quantity']];
        $subTotal     = $_POST[number_format($total, 2) ];
      }
    ?> 
   // i guess my post submit is wrong...

     <table class="table table-striped">
                    <tr>
                        <th colspan="7"><h3 class="text-center">Order details</h3></th>
                    </tr>
                    <tr  class="btn bg-success">
                        <th>Title</th>
                        <th>Slug</th>
                        <th>Description</th>
                    </tr>
                    <form method="post" action="cart.php">
                    <tr>
                        <td class="text-info" name="title"><?php echo $product['title']; ?></td>
                        <td class="text-info"><?php echo $product['slug']; ?> </td>
                        <td class="text-info"><?php echo $product['description']; ?> </td>

                            <input type="submit" name="submit" class="btn btn-success text-right" value="Checkout" onClick="return confirm('you will be redirected .....');" /> <!-- submit button -->

                </table>
All i need is to post to the database after clicking the submit button. Thank You.

To post data into database, you need to submit the form and convert the form variables into PHP variables.

In the form use a name for each field like

<input type="text" name="name" placeholder="Enter your name">

then, after form submission, collect the form data into php variables

$name = $_POST['name'];

Use this data in a mysql query to post into database.

$query = "INSERT INTO `table_name` (`slno`,`name`) VALUES ('1','".$name."'");
mysql_query($query);

You cannot post with out input tags. Make sure you have are submitting form from input elements. To get the posted values use the name for the input provided. Ex: $slug = $_POST['slug']; After getting the post values into variables insert them into database using mysql queries. I suggest you start from basics of insert query

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM