By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,781 Members | 1,399 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,781 IT Pros & Developers. It's quick & easy.

Editing and Updating Text

P: n/a
I'm trying to create a text editing and updating capability to help
someone who wants to maintain content on a web page without having to
know any HTML or use a web authoring tool and FTP'ng the contents.
I've already created a screen whereby the person can create new
content with a PHP program that inserts into a MySQL table. But, I'm
having a little trouble in creating the edit/update functionality.
Can somebody help me out? Thanks.

I created an edit screen called "teach_edit.php". Based upon some
search parameters on another HTML screen, it retrieves the appropriate
text from the database. It seems to allow on screen editing.
However, when I hit the Submit button, nothing happens. It's supposed
to call another program called "teach_update.php". Here's the code
for it.

<HTML>
<HEAD>
<TITLE>Teaching Edit Program</TITLE>
</HEAD>
<BODY>
<?php
@ $db = mysql_connect('localhost', '<db name>', '<password>');
if (!$db)
{
echo "Error: Could not connect to database. Please try again
later.";
exit;
}
mysql_select_db("<db>");
$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="teachnum" rows="1" cols="4"
wrap="off">';
echo htmlspecialchars($teachnum)."\n";
echo '</textarea>';
echo '<textarea name="title" rows="1" cols="60" wrap="off">';
echo htmlspecialchars($title)."\n";
echo '</textarea>';
echo '<textarea name="teaching" rows="20" cols="80"
wrap="on">';
echo htmlspecialchars($teaching)."\n";
echo '</textarea>';

}

?>

<input type=submit value="Update" name="teach_update.php">
</form>
</BODY>
</HTML>

The "teach_update.php" looks like this.

<HTML>
<HEAD>
<TITLE>Teaching Update Program</TITLE>
</HEAD>
<BODY>
<?php
@ $db = mysql_connect('localhost', '<database>', '<password>');
if (!$db)
{
echo "Error: Could not connect to database. Please try again
later.";
exit;
}
mysql_select_db("<db>");
$query = "update albert set title =". $title . " and teaching = ".
$teaching . " where teachnum =" . $teachnum ;
$result = mysql_query($query) or die("Could not update!");

if ($result)
{
echo mysql_affected_rows()." text item updated into
database.";
}
?>
</BODY>
</HTML>
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.