SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Stumped Again!

  1. #1
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stumped Again!

    I've modified Kevin Yank's script from his PHP/MySQL tutorial to suit the site I'm developing and have run into a problem with the script that edits information in the database. When I load the page it displays some of the information from the database but some fields are left blank. Ocassionally even one of the field is missing depending on which record I'm trying to pull. Invariably, it is the information being presented in textarea boxes (as opposed to text boxes) which are the problem. It's interesting that the page actually functions properly in all other repects as the information entered in the textareas will get updated with whatever is entered, it just doesn't display it initially which makes editing a chore.
    Anyway, at the risk of being longwinded, I posted a similar query a few weeks ago and got some helpful leads about using htmlspecialchars, and add/stipslashes but the problem persists. You'll notice in the script below I've commented out the htmlspecialschars, but it seems to make no difference either way. It's also curious that for some records information IS displayed in these textarea fields, but it will be truncated in unexpected ways.

    <!-- editdetails.php -->
    <HTML>
    <HEAD>
    <TITLE> Edit CD </TITLE>
    </HEAD>
    <BODY>
    <?php

    $dbcnx = @mysql_connect("localhost", "root", "");
    mysql_select_db("kyle");

    if (@$submit): // The CD's details have
    // been updated.

    $sql = "UPDATE details SET " .
    "id='$id', " .
    "cdid='$id', " .
    "title= '$title', " .
    "image='$image', " .
    "blurb='$blurb', " .
    "biopic='$biopic', " .
    "bio='$bio'," .
    "pic='$pic', " .
    "reviews='$reviews' " .
    "WHERE id='$id'";

    if (mysql_query($sql)) {
    echo("The CD information has been updated.<br>");
    } else {
    echo("Error updating CD details: " .
    mysql_error() . "</P>");
    }

    ?>

    <P><A HREF="details.php">Add/Edit detail page for another CD </A></P>

    <?php
    else: // Allow the user to edit the CD
    // with id=$id

    $cd=mysql_query("SELECT image, pic, biopic, blurb, title, bio, reviews " .
    "FROM details " .
    "WHERE id=$id");
    if (!$cd) {
    echo("<P>Error fetching CD details: " .
    mysql_error() . "</P>");
    exit();
    }

    $cd = mysql_fetch_array($cd);

    $image = $cd["image"];
    $pic = $cd["pic"];
    $biopic = $cd["biopic"];
    $blurb = $cd["blurb"];
    $title = $cd["title"];
    $bio = $cd["bio"];
    $reviews = $cd["reviews"];
    // Convert HTML special characters
    // in database value for use in
    // an HTML document.
    $title = htmlspecialchars($title);
    //$blurb = htmlspecialchars($blurb);
    //$bio = htmlspecialchars($bio);
    //$reviews = htmlspecialchars($reviews);



    ?>

    <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
    <P>Edit the CD Detailsbr>
    <P><b>Title</b> (to appear above blurb)<br>
    <input type="text" size="40" NAME="title" value="<?php
    echo($title);
    ?>">
    <P><b>Image Path/b><br>
    <input type="text" size="65" NAME="image" value="<?php
    echo($image);
    ?>">
    <P><b>Review Pic/b><br>
    <input type="text" size="65" NAME="pic" value="<?php
    echo($pic);
    ?>">
    <P><b>BioPic/b><br>
    <input type="text" size="65" NAME="biopic" value="<?php
    echo($biopic);
    ?>">
    <P><b>Blurb/b><br>
    <textarea cols="45" rows="6" NAME="blurb" value="<?php
    echo($blurb);
    ?>"></textarea>
    <P><b>Bio/b><BR>
    <textarea cols="45" rows="6" NAME="bio" value="<?php
    echo($bio);
    ?>"></textarea>
    <P><b>Reviews/b><BR>
    <textarea cols="45" rows="6" NAME="reviews" value="<?php
    echo($reviews);
    ?>"></textarea>

    </P>
    <INPUT TYPE=HIDDEN NAME="id" VALUE="<?php echo($id); ?>">
    <P><INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT"></P>
    </FORM>

    <?php endif; ?>

    </BODY>
    </HTML>

    By the way, since I'm blathering anyway, the blurb field is mediumtext, bio is longtext and reviews are mediumtext in MySQL.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its not a php problem its an html problem. textareas don't have a value attribute the content resides between the two tags. Like so:

    PHP Code:
    <textarea cols="45" rows="6" NAME="bio"><?=$bio?></textarea> 

    or

    <textarea cols="45" rows="6" NAME="reviews"><?php echo $reviews?></textarea>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yoo da man! I'll try and come up with some more dumb questions soon.

    Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •