Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with inserting into database from form

Status
Not open for further replies.

pinkerton2002

Programmer
Jan 11, 2005
15
NO
My code in the form is this:
<form method= "post" action="process.php">
Navn : <input type= 'text' name= '$navn' > <br><br>
Hjemmeside : <input type= 'text' name= '$hjemmeside' > <br><br>
Comment : <input type= 'text' name= '$kommentar' > <br><br>
<input type= 'submit' value= 'Skriv inn' >
</form>



My code in the process.php is this:
<?php

$navn = $_POST['$navn'];
$hjemmeside = $_POST['$hjemmeside'];
$melding = $_POST['$kommentar'];
$tid = date('D M j');
print ($navn);
print ($hjemmeside);
print ($melding);
print ($tid);
include ("conn.php");
mysql_select_db("elsrudc_bryllup") or die("Klarte ikke å velge databasen");
$sql = "INSERT INTO gjest(navn, hjemmeside, tid, melding) values($navn, $hjemmeside, $tid, $melding)" ;
mysql_query($sql) or die("klarte ikke å legge inn i tabell!");
header("location: gjestebok.php");


I've tested that my variables get their values, but still it will not put it into the table..

The connection to the db is working
The error I get is this:"klarte ikke å legge inn i tabell" Which means couldnt put into table!And is the error from the last DIE
The fields in my DB is like this:
ID-integer, auto_increment
navn-Varchar(35)
hjemmeside-Varchar(35)
tid-Varchar(35)
melding-text

I am very grateful for any answers that can help me with this problem

Thank you in advance
 
I would replace:

Navn : <input type= 'text' name= '$navn' >
Hjemmeside : <input type= 'text' name= '$hjemmeside' >
Comment : <input type= 'text' name= '$kommentar' >

with:

Navn : <input type= 'text' name= 'navn'>
Hjemmeside : <input type= 'text' name= 'hjemmeside'>
Comment : <input type= 'text' name= 'kommentar'>

Note I erase the $ character, this is a php var, not HTML. So the process.php should begin with:

$navn = $_POST['navn'];
$hjemmeside = $_POST['hjemmeside'];
$melding = $_POST['kommentar'];

note that all $_POST don't have the $ characters ( $_POST['navn'])
 
Ok,thank you, I tried, still the same message.
Her is the sql i get :
INSERT INTO gjest(navn, hjemmeside, tid, melding) values(dsf, fdsf, Mon Jan 31, asf)

This looks allright dont it?
All the rights are set for the user who inserts into the DB
 
not really...

replace:
$sql = "INSERT INTO gjest(navn, hjemmeside, tid, melding) values($navn, $hjemmeside, $tid, $melding)"

with:
$sql = "INSERT INTO gjest(navn, hjemmeside, tid, melding) values('$navn', '$hjemmeside', '$tid', '$melding')"

note that I add ' characters in the sql statment.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top