badeand Posted January 6, 2011 Share Posted January 6, 2011 Hi, I'm havin problem storing information from a textfield in a form to my mysql database. It stores every other field in my form but not the text area. I've attached my form and my process script. Could someone help me figure out what's wrong? Here are my form <form action="process/henvendelse_process.php" method="post"> <p> <label>Navn</label> <input name="Navn" type="text" size="30" value="Navn" /> <label>Telefon</label> <input name="Telefon" type="text" size="30" value="Telefon" /> <label>Epost</label> <input name="Epost" type="text" size="30" value="Epost" /> <label>Emne</label> <input name="Emne" type="text" size="20" value="Emne" /> <label>Henvendelse</label> <textarea name="Henv" Value="Henv" rows="5" cols="5" ></textarea> <br /> <input class="button" type="submit" value="Send" /> </p> </form> and here are my process file <?php $servername='localhost'; $dbusername='root'; $dbpassword=''; $dbname='store'; connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } ?> <?php if ($_SERVER['REQUEST_METHOD'] == "POST") { $Navn = $_POST['Navn']; $Telefon = $_POST['Telefon']; $Epost = $_POST['Epost']; $Emne = $_POST['Emne']; $Henvendelse = $_POST['Henv']; $SQL = " INSERT INTO henvendelser"; $SQL = $SQL . " (Navn, Telefon, Epost, Emne, Henv) VALUES "; $SQL = $SQL . " ('$Navn', '$Telefon', '$Epost', '$Emne', '$Henv') "; $result = mysql_db_query($dbname, "$SQL", $link); if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } print "<br>"; print "<br>"; print "<br>"; print "<br>"; print "<br>"; $forespørsel = "Henvendelsen er lagret"; echo '<p class="verdana" style="font-weight:normal;">' . $forespørsel . '</p\>'; } ?> Link to comment https://forums.phpfreaks.com/topic/223621-problem-storing-data-from-textarea-from-form-to-mysql-database/ Share on other sites More sharing options...
badeand Posted January 6, 2011 Author Share Posted January 6, 2011 I can see that I have an error in my variable $henvendelse but this does not matter, i've corrected it and it still dosent work.. Link to comment https://forums.phpfreaks.com/topic/223621-problem-storing-data-from-textarea-from-form-to-mysql-database/#findComment-1155916 Share on other sites More sharing options...
Drewdle Posted January 7, 2011 Share Posted January 7, 2011 I can see that I have an error in my variable $henvendelse but this does not matter, i've corrected it and it still dosent work.. I'm no expert, heck I wouldn't even class myself as an amateur but I have only recently created a similar function on my website and it works fine...the only difference is I have less code and the variable error you spotted yourself. This $Henvendelse = $_POST['Henv']; Should be this $Henv = $_POST['Henv']; Other than that I can't help...however, seems how my version works fine I've added it below, it's different from yours but essentially does the same thing so feel free to compare the two and see if it helps you. My form code: <form action="process.php" method="post"> <b>Your Location:</b> <input name="location" type="text"> <b>Your Website:</b> <input name="website" type="text"> <b>Your Name:</b> <input name="name" type="text"> <input type="submit" /> <input type="button" value="Cancel" onclick="history.go(-1);return false;" /> </form> And heres my process.php code: <?php $location = $_POST['location']; $userweb = $_POST['website']; $rname = $_POST['name']; mysql_query("INSERT INTO user (id, name, location, website) VALUES ('', '$rname', '$userweb, '$location') ") or die ("<b>Error:</b> Database info already exists!"); ?> Hope it helps. Link to comment https://forums.phpfreaks.com/topic/223621-problem-storing-data-from-textarea-from-form-to-mysql-database/#findComment-1156004 Share on other sites More sharing options...
badeand Posted January 9, 2011 Author Share Posted January 9, 2011 Thanks Drewdle After spending some hours reading the manual i did clean my own code a bit. So it looks more like yours. Link to comment https://forums.phpfreaks.com/topic/223621-problem-storing-data-from-textarea-from-form-to-mysql-database/#findComment-1157088 Share on other sites More sharing options...
Pikachu2000 Posted January 9, 2011 Share Posted January 9, 2011 You should never, ever, ever allow user supplied data into a query string without sanitizing/escaping/validating it. Link to comment https://forums.phpfreaks.com/topic/223621-problem-storing-data-from-textarea-from-form-to-mysql-database/#findComment-1157100 Share on other sites More sharing options...
badeand Posted January 9, 2011 Author Share Posted January 9, 2011 Thanks Pikachu2000 I've just started reading about form validation and found that it is a critical part Link to comment https://forums.phpfreaks.com/topic/223621-problem-storing-data-from-textarea-from-form-to-mysql-database/#findComment-1157103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.