After data insert , select and delete , data updation is also necessary for any web application.
Update syntax
update table_name
set column1= value1, column2=value2,coulmn_n=value_n
where column_name=Value ;
and PHP Query would be as follow :
$query = "UPDATE table_name
SET column1='value1',column2='value2'
WHERE column_name=any_value";
database : dbtuts
table : users
here i use following details for this tutorial
CREATE DATABASE `dbtuts` ;
CREATE TABLE `dbtuts`.`users` (
`user_id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`first_name` VARCHAR( 25 ) NOT NULL ,
`last_name` VARCHAR( 25 ) NOT NULL ,
`user_city` VARCHAR( 45 ) NOT NULL
) ENGINE = InnoDB;
i hope you should know that how to select data from database , so i come to the point.
first of all select the data from database table and display it on page.
Suppose following is the data :
data.php
mysql_connect("localhost","root","");
mysql_select_db("dbtuts");
$sql_query="SELECT * FROM users";
$result_set=mysql_query($sql_query);
?>
First Name
Last Name
City
Edit
if(mysql_num_rows($result_set)>0)Update syntax
update table_name
set column1= value1, column2=value2,coulmn_n=value_n
where column_name=Value ;
and PHP Query would be as follow :
$query = "UPDATE table_name
SET column1='value1',column2='value2'
WHERE column_name=any_value";
database : dbtuts
table : users
here i use following details for this tutorial
CREATE DATABASE `dbtuts` ;
CREATE TABLE `dbtuts`.`users` (
`user_id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`first_name` VARCHAR( 25 ) NOT NULL ,
`last_name` VARCHAR( 25 ) NOT NULL ,
`user_city` VARCHAR( 45 ) NOT NULL
) ENGINE = InnoDB;
i hope you should know that how to select data from database , so i come to the point.
first of all select the data from database table and display it on page.
Suppose following is the data :
data.php
mysql_connect("localhost","root","");
mysql_select_db("dbtuts");
$sql_query="SELECT * FROM users";
$result_set=mysql_query($sql_query);
?>
First Name
Last Name
City
Edit
{
while($row=mysql_fetch_row($result_set))
{
?>
}
}
else
{
?>
There's No data found !!!
}
?>
No comments:
Post a Comment