Saturday, December 22, 2018

mysql - sql syntax-error at inserting php post vars



        $username = $_POST['username'];
$score = $_POST['score'];


$mysqlhost = "localhost"; // MySQL-Host angeben
$mysqluser = "***********"; // MySQL-User angeben
$mysqlpwd = "***********"; // Passwort angeben

$connection = mysql_connect($mysqlhost, $mysqluser, $mysqlpwd) or die("Verbindungsversuch fehlgeschlagen");

$mysqldb="db2507004-seminarfach"; // Gewuenschte Datenbank angeben
mysql_select_db($mysqldb, $connection) or die("Konnte die Datenbank nicht waehlen.");

$sql = "INSERT INTO highscore (username, score) VALUES ('".$username."' , '".$score."');";

$query = "$connection, $sql";
$db_erg = mysql_query($query) or die("Anfrage fehlgeschlagen: " . mysql_error());
?>


always when i try to insert data into my table i get this 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 'Resource id #2, INSERT INTO highscore (username, score) VALUES ('peter silie' , ' at line 1" and i don't know what is wrong with it.



in my table username is a varchar and score an int.



hope someone could help me.



Answer



This is wrong: $query = "$connection, $sql";



$query = $sql;

$db_erg = mysql_query($query) or die("Anfrage fehlgeschlagen: " . mysql_error());

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...