开发者

how to update date using phpmysql

This is how,i inse开发者_开发问答rt data into db,but now,i want a particular column to update,how do i do?

<?php

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("form", $con);


$sql="INSERT INTO Customer (Name, Address, City, Pincode, State, Country, Phone, Mobile, Fax, Email, Website, Notes)
VALUES
('$_POST[name]','$_POST[address]','$_POST[city]','$_POST[pincode]','$_POST[state]','$_POST[country]','$_POST[phone]','$_POST[mobile]','$_POST[fax]','$_POST[email]','$_POST[url]','$_POST[notes]')";


if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con);

?>


A SQL update query looks like this:

UPDATE customers SET fieldname = newvalue WHERE id = '$id'

Complete syntax guide is at http://dev.mysql.com/doc/refman/5.0/en/update.html.

Also, you might want to have a look at filtering any user input before sending it the database. Using mysql_real_escape_string() is pretty much a necessity for security reasons.


Use a UPDATE query in pace of the INSERT.

Something like:

$sql="UPDATE Customer SET Name = $new_name WHERE....";

Rest of the code remains same.


Try and use mysqli_query to avoid SQL injection and escape the post values as well as assign to your own valuables before inserting to the DB.

like;

 (!mysql_query($sql,$con))

to Update any column in your Mysql DB,

sql = "UPDATE customers SET columnname = newvalue WHERE id = '$id'";


if (!mysqli_query($sql,$con)) 
{ die('Error: ' . mysqli_error());
 } 
$con->close;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜