Jump to content

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

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.