lamialex Posted January 9, 2008 Share Posted January 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/85176-problem-with-a-textarea-field-in-a-form/ Share on other sites More sharing options...
Zuti Posted January 9, 2008 Share Posted January 9, 2008 Use <textarea name=something"></textarea> not <textarea ... /></ And you should really escape your post variables if the form is going to be used by others. Quote Link to comment https://forums.phpfreaks.com/topic/85176-problem-with-a-textarea-field-in-a-form/#findComment-434859 Share on other sites More sharing options...
monkeytooth Posted January 13, 2008 Share Posted January 13, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/85176-problem-with-a-textarea-field-in-a-form/#findComment-437894 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.