

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to write PHP script to update an existing MySQL table?
We can use the SQL UPDATE command with or without the WHERE CLAUSE in the PHP function – mysql_query(). This function will execute the SQL command in a similar way it is executed at the mysql> prompt. To illustrate it we are having the following example −
Example
In this example, we are writing a PHP script to update the field named tutorial_title for a record having turorial_id as 3.
<?php $dbhost = 'localhost:3036'; $dbuser = 'root'; $dbpass = 'rootpassword'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = 'UPDATE tutorials_tbl SET tutorial_title="Learning JAVA" WHERE tutorial_id=3'; mysql_select_db('TUTORIALS'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not update data: ' . mysql_error()); } echo "Updated data successfully\n"; mysql_close($conn); ?>
- Related Questions & Answers
- How to write PHP script to delete data from an existing MySQL table?
- How can we delete an existing MySQL table by using PHP script?
- How can we insert data into an existing MySQL table by using PHP script?
- Which PHP functions are used in the PHP script to fetch data from an existing MySQL table?
- Write an example to establish MySQL database connection using PHP script?
- How to write PHP script to fetch data, based on some conditions, from MySQL table?
- Which PHP function is used to delete an existing MySQL table?
- How to add columns to an existing MySQL table?
- How to add current date to an existing MySQL table?
- How to write PHP script by using LIKE clause inside it to match the data from MySQL table?
- Which PHP function is used to insert data into an existing MySQL table?
- How to rename a column in an existing MySQL table?
- How to write PHP script by using ORDER BY clause inside it to sort the data of MySQL table?
- How to batch update MySQL table?
- Create MySQL query to create a table from an existing table?
Advertisements