This is a serious problem for me. I just started working with AJAX and PHP but I can’t even get off to a good start. Any help is greatly appreciated. As result of this code, I receive a blank page, as if the query has been performed, but there are no changes in database.
<?php
$user = "login";
$pass = "password";
$con = mysql_connect("localhost","qwerty","qwerty");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database_sky", $con);
mysql_query("INSERT INTO players (id, username, password) VALUES ('',$user, $pass)");
mysql_close($con);
?>
I have no idea whats going on. Im using Apache 2.2, PHP 5, MySql 4.1
your variables are never wrapped in single quotes (they are meant to be strings).
try:
Whereas your original code is evaluated like this:
this doesn’t work because you need to (most likely) enter strings. You wrote
john, not'john'I’d recommend doing something like
$query = "INSERT INTO .......";This way you can
a)
echo $query;Take the string it outputs and plug that into your PhpMyAdmin (or whatever you use as an interface to your database.b) you can then do
mysql_query($query). This makes it easier to organize (for me, in my opinion).🙂