Form inserting updating and deleting data using php
Notice that we’ve used POST method for the form and given name for each field – name and description – to reference them in the next PHP page, ‘insert_records.php’ as defined in the ‘action’ property of the form.
You’ll also see the newly added product information.
//Include the ‘db_connection.php’ file here to connect with the server and select database include(‘db_connection.php’); //Grab the values into easy accessible variables $prodname = $_POST[‘name’]; $proddesc = $_POST[‘description’]; //Initialize the My SQL Query to insert the above data into the table $sql_insert = “Insert into tbl_products Values($prodname, $proddesc)”; //execute the above SQL query $result = mysql_query($sql_insert); //If the above code executes successfully, then redirect user to the main page If($result) ?
Before inserting data, remember that we always need to connect with the server and then, select the table we want to insert it.
There are still few more data manipulations operations that we you perform – adding, updating, and deleting data from the database.
In this article, we’ll actually insert data into the table we created – ‘tbl_products.’ To insert data, first we’ll need a simple Web form, ‘product_form.php’, with input fields to let Web administrators to enter product information – name and description. Web forms are amazing as they not only allow users to enter information, but they also send that information to another Web page to process it.
As we know, in the previous article, we created a PHP page that used to display all the records from the table itself.