I'm trying to retrieve a text value from a MySQL database, put it into
an updateable form, allow edits, and send back the edited text back
into the MySQL database. I've been able to successfully retrieve the
text and put it into the editable form, using htmlspecialchars
function. But, I can't find a way of accepting the edited text and
sending back to the database.
Here's my code for retrieval.
<?php
@ $db = mysql_connect('localhost', '<database>', '<password>');
if (!$db)
{
echo "Error: Could not connect to database. Please try again
later.";
exit;
}
mysql_select_db("<database>");
$query = "select * from albert where ".$searchtype." like
'%".$searchterm."%'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$title = $row['title'];
$teaching = $row['teaching'];
$teaching = wordwrap($teaching, 60, "\n", 1);
$teachnum = $row['teachnum'];
}
if ($result)
{
echo '<textarea name="newteachnum" rows="1" cols="4"
wrap="off">';
echo htmlspecialchars($teachnum)."\n";
echo '</textarea>';
echo '<textarea name="newtitle" rows="1" cols="60"
wrap="off">';
echo htmlspecialchars($title)."\n";
echo '</textarea>';
echo '<textarea name="newteaching" rows="20" cols="80"
wrap="on">';
echo htmlspecialchars($teaching)."\n";
echo '</textarea>';
}
?>
<form action="teach_update.php" method="post">
<input type=submit value="Submit">
</form>
Here's the code to update the database.
<?php
@ $db = mysql_connect('localhost', '<database>', '<password>');
if (!$db)
{
echo "Error: Could not connect to database. Please try again
later.";
exit;
}
mysql_select_db("<database>");
$newtitle = addslashes($newtitle);
$newteaching = addslashes($newteaching);
$newteachnum = addslashes($newteachnum);
$query = "update albert set title =". $newtitle . " and teaching =
". $newteaching . " where teachnum =" . $newteachnum ;
print $query; //the print shows nulls for $newtitle, $newteaching,
and $newteachnum. It seems like those values are not being held in
memory from the calling program teach_edit.php
//$result = mysql_query($query) or die("Could not update!");
// if ($result)
// {
// echo mysql_affected_rows()." text item updated into
database.";
// }
?>
Can someone tell me what I'm missing? Thanks in advance.