Updating MYSQL through a textarea field

Hi Guys,

i had some trouble a few days ago updating a mysql field, i had 2 text fields and 2 textarea fields, both the text fields updated ok through this query:


    $description = mysql_escape_string($_POST['description']);

   // Update Database put the variables in a query
    $query = "UPDATE membership SET description='$description' WHERE username='$username'";

    $result = mysql_query($query);

    if ($result) {
     echo "<p>Thank you. Your profile <b>description</b> has been updated.</p>";
}

but for some reason the textarea fields don’t seem to update heres the code for 1:

<textarea name="description" rows="10"><?php echo "$description"; ?></textarea>

is there something different i need to do, from a text field from a textarea field?

thanks a lot guys

Graham

Where are you grabbing your POST data? Make sure your POST data is coming through.

From your DB query, i don’t see where you are inserting/updating the DB from the POST data.

Try this:

$description = mysql_escape_string($_POST['description']);
$username = mysql_escape_string($_POST['username']);
// Update Database put the variables in a query
$query = "UPDATE membership SET description='$description' WHERE username='$username'";
$result = mysql_query($query);
if($result) {
  echo "<p>Thank you. Your profile <b>description</b> has been updated.</p>";
}

Double check the names of the username and description fields I have listed on the first 2 lines to make sure they match with your form. This should help.

Make sure your textareas all have the name=“” attribute. If that all does not work post all of your code.

Hi Mate,

forgot to add it in, edited post:)

Graham

hmm thanks guys,

still no joy heres the full code:

form:

<form action="edit_description_done.php" method="post">
   <table width="400" border="0" bordercolor="black" cellspacing="2" cellpadding="2">
     <tr>
      <td align="right" bgcolor="#E2E2E2">Edit Your Profile Description:</td>
     <td bgcolor="#E2E2E2"><textarea name="description" rows="10"><?php echo "$description"; ?></textarea></td>
     </tr>
     <tr>
      <td bgcolor="#E2E2E2">&nbsp;</td><input type="hidden" name="username" value="<?php echo "$username"; ?>" >
     <td bgcolor="#E2E2E2"><input type="submit" name="Submit" value="Update Description!"></td>
     </table>

edit/update code

<?php
     // For register_global on PHP settings//////////////////////////////////////////////
     $member = $_COOKIE['member'];

     session_start(); // you must put this to read session variables/////////////////////

     if (empty($member) || !isset($member)) // fail to read the browser cookie///////////
     {
     // Try to read session
     if (empty($_SESSION['member']) || !isset($_SESSION['member']))
     {
           header("Location: login.php"); // redirect user to login//////////////////////
           exit;
     } else {
          $member = $_SESSION['member'];
  }
}
     //Includes... //////////////////////////////////////////////////////////////////////
     include("includes/db_connection.php");
     include("includes/constants.php");
     include("includes/header.php");
     include("includes/loginnav.php");
?>
<p align="left">Welcome, <b><font color="red"><? echo $_COOKIE['member'] ?></font></b>! (<a href="logout.php">Logout</a>) - [ <a href="change_password.php">Change Password Or E-mail Address</a> ] - [ <a href="edit_profile.php">Edit Profile</a> ] - [ <a href="upload_photo.php">Upload Photo</a> ]</p>
<?php
     // Start of Update Code

    $description = mysql_escape_string($_POST['description']);
    $username = mysql_escape_string($_POST['username']);

    // Update Database put the variables in a query
    $query = "UPDATE membership SET description='$description' WHERE username='$username'";
    $result = mysql_query($query);
    if($result) {
      echo "<p>Thank you. Your profile <b>description</b> has been updated.</p>";
}
?>

Thanks guys

Graham

if you echo your $_POST[‘description’] do you see the data or is it empty?

What version of PHP are you using?

mysql_real_escape_string is the newer version of mysql_escape_string. You should use that if possible.

Also, add this to your mysql_query


if(!($result = mysql_query($query)){
    die(mysql_error());
}

See what error you are getting from your query.

Hi Mate,

i echoed out the information to be updated it was fine, i’m using the latest version of php that comes with wamp, also replaced mysql_real_escape_string in the appropriate places, i don’t really get a ny errors as such i put new data in the fields, press update it then displays the “edited successfully message” but it hasn’t updated anyhting, the text fields update perfectly, it just seems to be when i use a <textarea> for some reason.

cheers

Graham