Reputation: 23
What im trying to do is to present the text in the 'text' row of the table about in a textarea... (that was a strange sentence) and i should be able to add/remove/edit text in that textarea and then press save to update it...
When trying the about table gets wiped of all data...
<?php
if(isset($_POST['submit_about']))
{
mysql_query("UPDATE about SET `text` = '$row['text']'");
}
// get result from database
$result = mysql_query("SELECT * FROM about")
or die(mysql_error());
// present the result
while($row = mysql_fetch_array( $result )) {
echo "<form method='post' action='uc_admin.php'>
<textarea name='text' rows='8'>" . $row['text'] . "</textarea>
<br />
<button type='submit' name='submit_about' class='btn'>Save</button>";
}
?>
Upvotes: 0
Views: 3507
Reputation: 287
You should try following code.
mysql_query("UPDATE about SET `text` = '$_POST['text']' WHERE DBid='dbid'");
DBid is your data base table primary id.
Upvotes: 0
Reputation: 324650
Your update query should look like:
mysql_query("update `about` set `text`='".mysql_real_escape_string($_POST['text'])."'");
Upvotes: 1
Reputation: 12836
change
mysql_query("UPDATE about SET `text` = '$row['text']'");
to
mysql_query("UPDATE about SET `text` = '".mysql_real_escape_string($_POST['text'])."'");
Also, try to move to mysqli or PDO..
Upvotes: 2