Hallo, ich komme einfach nicht auf eine Lösung wo hier der Fehler liegt. Das mit den Variablen hab ich so gemacht weil ich dachte vielleicht geht es wenn ich den Wert aus einem Forumlar erst in eine Variable übergebe, ich weiß dass ich direkt das $_POST reinschreiben könnte in den Inser Befehl. Wäre nett wenn kurz jemand helfen könnte.
Es geht auch nicht wenn ich die Values in '....' stecke
$name = $_POST['vorname'];
$alter = $_POST['alter'];
$groesse = $_POST['groesse'];
$haarfarbe = $_POST['haarfarbe'];
$cool = $_POST['istcool'];
$con = mysql_connect("localhost","felix","luftballon");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("kontakte", $con);
$sql="INSERT INTO tab_freunde (Name, Alter, Groesse, Haarfarbe, cool)
VALUES
($name, $alter, $groesse, $haarfarbe, $cool)";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 person added";
mysql_close($con);
Fehlermeldung:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Alter, Groesse, Haarfarbe, cool) VALUES (, , , , )' at line 1
Es geht auch nicht wenn ich die Values in '....' stecke
$name = $_POST['vorname'];
$alter = $_POST['alter'];
$groesse = $_POST['groesse'];
$haarfarbe = $_POST['haarfarbe'];
$cool = $_POST['istcool'];
$con = mysql_connect("localhost","felix","luftballon");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("kontakte", $con);
$sql="INSERT INTO tab_freunde (Name, Alter, Groesse, Haarfarbe, cool)
VALUES
($name, $alter, $groesse, $haarfarbe, $cool)";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 person added";
mysql_close($con);
Fehlermeldung:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Alter, Groesse, Haarfarbe, cool) VALUES (, , , , )' at line 1