Log in

View Full Version : update multiple feilds



khaja.jab
06-13-2012, 08:23 AM
i want update multiple rows with different text.
My table structure:
+----+---------+
| id | content |
+----+---------+
| 2 | abc |
+----+---------+
| 14 | def |
+----+---------+
I have a code. but it was updating that particular id only.
i want to update multiple ids.
Below is my code: can any one provide the full code please...


<?php
$hostname = "localhost";
$username = "";
$password = "";
$database = "";

// Connect to the database
mysql_connect($hostname, $username, $password) OR DIE("Unable to connect");
mysql_select_db("$database") or die("Unable to select database");

if (isset($_POST['ud_date'])) {
$query = sprintf("UPDATE test_mysql SET content='%s' WHERE id=%d",
mysql_real_escape_string($_POST['ud_date']),
2);
if (mysql_query($query)) {
echo 'update query succeeded';
} else {
else echo 'update query failed';
}
} else {
echo 'please submit the form';
}


please give the exact code.

wtl-php
06-14-2012, 02:59 PM
first of all you have mistake in line 18

else echo 'update query failed';

remove else

second

follow this might help you

http://www.phpeasystep.com/mysql/10.html