|
-
Jun 14th, 2012, 07:23 AM
#1
Thread Starter
New Member
update multiple columns
i want to update my columns with different content.
This is my table structure
+----+---------+
| id | content |
+----+---------+
| 2 | abc |
+----+---------+
| 14 | def |
+----+---------+
From my code i am able to update only single column only.
can anyone help me please...
PHP Code:
<?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';
}
-
Jun 14th, 2012, 10:14 AM
#2
Re: update multiple columns
There is only one column you can (or should) update.... the Content column. the ID column is your primary key, so you really shouldn't be changing that. ....so... I'm not sure what the problem is... unless there's more to the table structure that you're not telling us. Also, the use of ud_date as the ID field in the post form seems counterintuitive. I would expect something called ud_date to contain a date value...
-tg
-
Jun 15th, 2012, 12:28 AM
#3
Thread Starter
New Member
Re: update multiple columns
yes boss that content column only,
i want to update that content columns with different text.
-
Jun 22nd, 2012, 05:12 PM
#4
Hyperactive Member
Re: update multiple columns
Are you saying you want your data to look like this:
+----+---------+
| id | content |
+----+---------+
| 2 | new |
+----+---------+
| 14 | new |
+----+---------+
updating id=2 and id=14 to a new value?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|