Jump to content

Problem with a textarea field in a form


lamialex

Recommended Posts

Hello,

 

I have this simple html form that I use to insert an element in MySQL database :

 


<html>
<head>
<title>Insert File To MySQL Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>

<form action="insert.php" method="post">
Name: <input type="text" name="name" />
Price: <input type="text" name="price" />
Description: <textarea name="description" /></textarea>
Image: <input type="text" name="image" />
<input type="submit" />
</form>

</body>
</html>

 

My file insert.php looks like that :

 


<?php

$dbhost = 'localhost';
$dbuser = 'xxxx';
$dbpass = 'xxxx';
$dbname = 'items';

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

$query="INSERT INTO sellitems (name, imagepath, description, price) VALUES ('$_POST[name]','$_POST[image]','$_POST[description]','$_POST[price]')";

if (!mysql_query($query))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($conn);
?>

 

Basically, all the fields name, price and image are correctly sent via POST but not the field description which is a textarea. $_POST[description] remains empty.

 

I did an echo $_POST[description]; but it shows that $_POST[description] is empty whatever I type in it, even when it's just one character.

 

I'm a bit lost to be honest and it seems so simple this code I've done.

 

Thanks for your help.

Alexandra

Link to comment
https://forums.phpfreaks.com/topic/85176-problem-with-a-textarea-field-in-a-form/
Share on other sites

dunno if it makes a diffrence for you or not.. but when I use $_POST $_GET i have to use a single or double quote in the var..

 

you have:

$_POST[name]

 

when I do that I usually get either an error or draw a blank presumably cause its not exactly looking for what I want

but if i add the quotes accordingly my problem goes away..

 

$_POST["name"]

 

this might just be me, and my luck but overall thats how i learned it originally.. this is just an observation though

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.