Jump to content

Problem storing data from textarea from form to MYSQL database


badeand

Recommended Posts

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\>';







} 





?> 

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.

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.