Visa ett inlägg
Oläst 2009-06-16, 13:35 #1
youheardit youheardit är inte uppkopplad
Har WN som tidsfördriv
 
Reg.datum: Oct 2008
Inlägg: 1 168
youheardit youheardit är inte uppkopplad
Har WN som tidsfördriv
 
Reg.datum: Oct 2008
Inlägg: 1 168
Hej gott folk
Har ett litet problem med att köra insert into i mySQL!

Så här ser koden ut:
Kod:
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
 *{
 *die('Could not connect: ' . mysql_error());
 *}

mysql_select_db("my_db", $con);

$sql="INSERT INTO products (name, desc, points, img)
VALUES
('".$_POST['name']."','".$_POST['desc']."','".$_POST['points']."','".$_POST['img']."')";

if (!mysql_query($sql, $con))
 *{
 *die('Error: ' . mysql_error());
 *}

echo "Added!";
}
och får error:
Kod:
Error: 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 '2, 3, 4) VALUES ('1','2','3','4')' at line 1
Men detta funkar till en annan tabell men inte annars!

Kod:
$result = mysql_query("INSERT INTO table (1, 2, 3, 4)
VALUES ('".$_POST['1']."', '".$_POST['2']."', '".$_POST['3']."', '".$_POST['4']."')");
Mysql Connect är längst upp på sidan!

Tacksam för svar!

//Philip Andersson
youheardit är inte uppkopplad   Svara med citatSvara med citat