This example gives a demo to update record in mysql database table using html form in php application. First we will created a html form and used POST method.
PHP MySQL Record Update Using Form Example:
This example gives a demo to update record in mysql database table using html form in php application. First we will created a html form and used POST method.
The existing database user table is:
Example:
<?php $connection = mysql_connect("localhost","root","root"); if (!$connection) { die('PHP Mysql database connection could not connect : ' . mysql_error()); } else{ $db_name = "php_mysql"; mysql_select_db($db_name, $connection); if(isset($_POST['submit'])){ if($_POST['user_name']!="" && $_POST['user_email']!="" && $_POST['user_address']!=""){ $update_sql = "UPDATE user SET user_name='".$_POST['user_name']."', user_email='".$_POST['user_email']."', user_address='".$_POST['user_address']."' WHERE user_id=1;"; mysql_query($update_sql, $connection); echo "Last update record has id : 1."; } } } ?> <html> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table> <tr> <td>User Name : </td> <td><input type="text" name="user_name" /></td> <td></td> </tr> <tr> <td>Email : </td> <td><input type="text" name="user_email" /></td> <td></td> </tr> <tr> <td>Address : </td> <td><input type="text" name="user_address" /></td> <td></td> </tr> <tr> <td></td> <td><input type="submit" name='submit' value="Submit"/></td> <td></td> </tr> </table> </form> </body> </html>
After running this example the output is:
Browser Output:
And after submission,
And the database update user table is:
[ 0 ] Comments