saftutorials.com

HTML

How to download HTMl Editors

How to use HTML tags

How to Comment in HTML

How to create an HTML link

How to link to a specific part of a page HTML

How to Insert Images with HTML

How to insert audio in HTML

How to insert videos in HTML

How to use Table Tag in HTML

How to Use HTML List Elements

How to use HTML Iframe

How to use HTML Symbols

How to use HTML Color Codes

How to Create HTML From

How to learn HTML

CSS

How to use CSS Background

JS

PHP

How to redirect to another page using PHP

How to get last inserted id in MySQL using PHP

How to learn php

How to insert a row into database by using PHP

How to fetch data from table by using php

How to print table data by using while loop in php

How to perform search operation into database by using php

MySQL

How to create Table in PHP MySQL?

How to Insert Data Into MySQL Database Table Using PHP?

How to Select Data from MySQL Database Tables Using PHP

How to Update data in MySQL Database Table using PHP

How to Delete Data from MySQL using PHP

How to make MySQL query ORDER BY conditions

How to Select LIMIT data in PHP MySQL

SQL

BOOTSTRAP

AJAX

DATATABLE

SEO

EARNING

GOOGLE

FACEBOOK

YOUTUBE

WordPress

How to Install WordPress?

How to use WordPress Dashboard?

How to Install Plugins in WordPress?

How to Customize WordPress Plugins?

How to Change General Settings in WordPress?

How to Change Writing Settings in WordPress

How to Setup the Reading Settings in WordPress

How to Setup the Discussion Settings in WordPress

How to Setup the Media Settings in WordPress

How to Setup the Permalink Settings in WordPress

How to Setup the Plugin Settings in WordPress

How to Add Categories to WordPress

How to Edit Category in WordPress

How to Delete Category in WordPress

How to Arrange Category in WordPress

How to Add a new Post in WordPress

How to Edit Post in WordPress

How to Delete Post in WordPress

How to Review Post in WordPress

How to add Media in WordPress

How to Edit Media in WordPress

How to add a Page in WordPress

How to Delete Media in WordPress

How to Add Page in WordPress

How to Edit Pages in WordPress

How to Learn WordPress

How to Delete Page in WordPress

How to add New Tag in WordPress

How to Edit Tags in WordPress

How to Delete Tags in WordPress

How to Update data in MySQL Database Table using PHP

Answer: Create the MySQL query for updating data into a table and then execute it with mysql_query() function. We can update data of a table by using MYSQL UPDATE statement.


Syntax of MYSQL UPDATE statement

UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value


Below is a simple example to update records into student table

<html>
 <head>
  <title>Update a Record in MySQL Database</title>
 </head>
 <body>
    <?php
    if(isset($_POST['update'])) {
    $database_host = 'localhost:3036';
    $database_user = 'root';
    $database_pass = '';
    $conn = mysql_connect($database_host, $database_user, $database_pass);
 
    if(! $conn ) {
      die('Could not connect: ' . mysql_error());
    }else{
      echo 'Connected successfully\n';
    }
  
    $selected_or_not = mysql_select_db( 'xyz_school' );
    if(! $selected_or_not ) {
      die('Not Selected xyz_school database');
    }else{
      echo 'Selected xyz_school database';
    }
        
        $student_id = $_POST['student_id'];
        $student_name = $_POST['student_name']
        $student_address = $_POST['student_address'];
        
        $sql = "UPDATE student SET student_name = $student_name, student_address= $student_address WHERE student_id = $student_id" ;
        
        $retval = mysql_query( $sql, $conn );
        
        if(! $retval ) {
           die('Could not update data: ' . mysql_error());
        }
        echo "Updated data successfully\n";
        
        mysql_close($conn);
     }else {
    ?>
   <form method="post" action="<?php $_PHP_SELF ?>">
 <table width="400" border="0" cellspacing="1" cellpadding="2">
 
<tr>
<td width="100">Student ID</td>
<td><input name="student_id" type="text" id="student_id"></td>
</tr>
 
<tr>
<td width="100">Student Name</td>
<td><input name="student_name" type="text" id="student_name"></td>
</tr>
 
<tr>
<td width="100">Enrollment No </td>
<td><input name="enrollment_no" type="text" id="enrollment_no"> </td>
</tr>
 
<tr>
<td width="100">Address </td>
<td><textarea name="student_address" id="student_address"></textarea></td>
</tr>
 
<tr>
<td width="100"> </td>
<td><input name="update" type="submit" id="update" value="Update"></td>
</tr>
 
 </table>
   </form>
    <?php
     }
    ?>
 </body>
</html>

Demo Update Form where update and Student information by using his Unique Student ID
Student ID
Student Name
Enrollment No
Address


Multiple Data Update in one Query

If you want to Update multiple data in one Query like Update all Student Semester from on Query then you should only one change for this:

$sql = "UPDATE student SET student_name = $student_name, student_address= $student_address WHERE semester or column_name = 'with_you_value' " ;





Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic