Editing and Updating Text

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Kaku

    Editing and Updating Text

    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.p hp". Here's the code
    for it.

    <HTML>
    <HEAD>
    <TITLE>Teachi ng 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 ".$searchty pe." like
    '%".$searchterm ."%'";

    $result = mysql_query($qu ery);
    while ($row = mysql_fetch_arr ay($result)) {
    $title = $row['title'];
    $teaching = $row['teaching'];
    $teaching = wordwrap($teach ing, 60, "\n", 1);
    $teachnum = $row['teachnum'];
    }
    if ($result)
    {

    echo '<textarea name="teachnum" rows="1" cols="4"
    wrap="off">';
    echo htmlspecialchar s($teachnum)."\ n";
    echo '</textarea>';
    echo '<textarea name="title" rows="1" cols="60" wrap="off">';
    echo htmlspecialchar s($title)."\n";
    echo '</textarea>';
    echo '<textarea name="teaching" rows="20" cols="80"
    wrap="on">';
    echo htmlspecialchar s($teaching)."\ n";
    echo '</textarea>';

    }

    ?>

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

    The "teach_update.p hp" looks like this.

    <HTML>
    <HEAD>
    <TITLE>Teachi ng 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($qu ery) or die("Could not update!");

    if ($result)
    {
    echo mysql_affected_ rows()." text item updated into
    database.";
    }
    ?>
    </BODY>
    </HTML>
Working...