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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT doesn´t works... 1

Status
Not open for further replies.

Gast

Technical User
Feb 14, 2002
2
DE
Hi all,
i have a, maybe very simple ;), problem with my database(MySQL+PHP4). if want to use variables in this code it doesen´t works. Would be very happy if you could help:


$verbindung= mysql_connect("localhost","root","root");

if (!$verbindung) { echo "error"; }
else { echo "ok"; }

$name= "Test";
$preis= "12.00";
$Beschreibung= "bla";
$tabel= "angebote";

$query = 'INSERT $tabel (name,preis,beschreibung) VALUES ($name,$preis,$beschreibung)';

$erg = mysql_db_query(shop,$query,$verbindung);

mysql_close($verbindung);
 
You might need quote characters (') around your variables in your VALUES clause:

Code:
$query = 'INSERT $tabel(name,preis,beschreibung) VALUES ('$name','$preis','$breschreibung')';

DjangMan
 
are you entering the name, preis variables into a table? if so then it should be insert into $tabel..
also i don't think u need the quotes around the INSERT statement..

hope that helped..
arif X-) s-)
 
hmm thx,
but it still doesn´t work.. it seems that the variables are the problem, cause if i put normal text there instead it works..

 
Try this:

Code:
$query = "INSERT INTO '$tabel'(name,preis,beschreibung) VALUES ('$name','$preis','$breschreibung')";

I've added the " character around the whole string and ' characters around your table name.

DjangMan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top