Jump to content

Recommended Posts

I'm trying to make an editable form that populates with the fields from a database, but my textarea field isn't working properly. To display the data from the textarea's field, I'm using the following syntax:

 

 


while($image=mysql_fetch_array($all_records_res)){
$id = $image['id'];
$cut = $image['cut'];
$color = $image['color'];
$carats = $image['carats'];
$clarity = $image['clarity'];
$size = $image['size'];
$type = $image['type'];
$other = $image['other'];
$total = $image['total'];
$certificate = $image['certificate'];
$value = $image['value'];
$name = $image['name'];
$desc = $image['desc'];
$item_no = $image['item_no'];
$metal = $image['metal'];
$angle1 = $image['image'];
$angle2 = $image['image2'];


echo "<tr>
<td>Item Number:</td>
<td><input type='text' id='item_no' name='item_no' value='$item_no' /></td>
</tr>
<tr>
<td>Item Name:</td>
<td><input type='text' id='item_name' name='item_name' value='$name' /></td>
</tr>
<tr>
<td>Item Description:</td>
<td><textarea id='desc' name='desc' rows='10' cols='40'>$desc</textarea></td>
</tr>
<tr>
<td>Item Type:</td>
<td><input type='text' id='type' name='type' value='$type' /></td>
</tr>
<tr>
<td>Value:</td>
<td><input type='text' id='value' name='value' value='$value' /></td>
</tr>
<tr>
<td>Gem Cut:</td>
<td><input type='text' id='cut' name='cut' value='$cut' /></td>
</tr>
<tr>
<tr>
<td>Gem Color:</td>
<td><input type='text' id='color' name='color' value='$color' /></td>
</tr>
<tr>
<td>Gem Carats:</td>
<td><input type='text' id='carats' name='carats' value='$carats' /></td>
</tr>...

 

 

And the php page that is supposed to update is shown here:

 

 


<?php


$cut = $_POST['cut'];
$color = $_POST['color'];
$carats = $_POST['carats'];
$clarity = $_POST['clarity'];
$size = $_POST['size'];
$metal = $_POST['metal'];
$other = $_POST['other'];
$total = $_POST['total'];
$certificate = $_POST['certificate'];
$value = $_POST['value'];
$angle1 = $_POST['angle1'];
$name = $_POST['item_name'];
$desc = $_POST['desc'];
$item_no = $_POST['item_no'];
$type = $_POST['type'];
$angle2 = $_POST['angel2'];


$dbhost = 'localhost';
$dbuser = 'jhrevell_jewelry';
$dbpass = 'jewelry123';


$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');


$dbname = 'jhrevell_jewelry';
mysql_select_db($dbname);


mysql_query ("UPDATE gallery SET cut = '$cut', color = '$color', carats = '$carats', clarity = '$clarity', size = '$size', metal = '$metal', other = '$other', total = '$total', certificate = '$certificate', value = '$value', image = '$angle1', name = '$name', item_no = '$item_no', type = '$type', image2 = '$angle2', desc = '$desc' WHERE id = '$_GET[id]'");


header('Location: http://midwestcreativeconsulting.com/jhrevell/manage');


?>

 

 

But the desc field (the textarea one) is not working. I'm thinking it's because I have the php variable set on the form, but I'm not sure. Is there another way to do this? Please, can anyone help?

Why do you think it's not working? Errors?

 

Since you don't check to make sure the query is working...

 

Also, never trust user input. You don't validate any input. At the very least process all string data through mysql_real_escape_string

 

Ken

What is not working is when I try to type something else into the textarea to save it, it is not updating in the database. Sorry if I miscommunicated that.

 

 

And thank you for reminding me about the validation. I'm going to have to work on that next ;-)

 

 

By the way, everything else is being updated in the database, the only one that doesn't work in the desc one. Not sure exactly why except for what I already stated.

If you had done some error checking on the query like this,

<?php
$q = "UPDATE gallery SET cut = '$cut', color = '$color', carats = '$carats', clarity = '$clarity', size = '$size', metal = '$metal', other = '$other', total = '$total', certificate = '$certificate', value = '$value', image = '$angle1', name = '$name', item_no = '$item_no', type = '$type', image2 = '$angle2', desc = '$desc' WHERE id = '$_GET[id]'";
$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
?>

You would have gotten an error on the query because "desc" is a reservered word in MySQL. You need to either rename the field or put backticks ` around the word:

<?php
$q = "UPDATE gallery SET cut = '$cut', color = '$color', carats = '$carats', clarity = '$clarity', size = '$size', metal = '$metal', other = '$other', total = '$total', certificate = '$certificate', value = '$value', image = '$angle1', name = '$name', item_no = '$item_no', type = '$type', image2 = '$angle2', `desc` = '$desc' WHERE id = '$_GET[id]'";
$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
?>

 

Ken

  • 2 weeks later...

kenrbnsn,

 

 

Thank you so much for your help! I am terrible at not setting up error checking. I will try to remember to start using it more often. Your suggestion worked perfectly! Thank you again sooo much!!!!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.