Reputation: 157
I'm trying to update a row in my database but it's not running.
Below is the current script I have that gets values from an ajax call. I've checked the call and it is sending the right information. know that I do have the connection values at the top of the script but did not include them here.
// Opens a connection to a MySQL server
$connection = mysql_connect($host, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
} // Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die("Can\'t use db : " . mysql_error());
}
// Store INFORMATION
$name = $_POST['name'];
$website = $_POST['website'];
$address = $_POST['address'];
$request_url = $base_url . "&q=" . urlencode($address);
$csv = file_get_contents($request_url) or die("url not loading");
$csvSplit = split(",", $csv);
$status = $csvSplit[0];
$lat = $csvSplit[2];
$lng = $csvSplit[3];
$state = $_POST['state'];
$ident = $_POST['ident'];
$query = "UPDATE markers SET name = '".$name."', website = '".$website."',address = '".$address."',lat = '".$lat."',lng = '".$lng."',state = '".$state."'WHERE id = '" . $ident . "'";
mysql_query($query) or die(mysql_error());
?>
I'm still very new at this, can someone explain why it's not working?
Upvotes: 0
Views: 598
Reputation: 21191
If your id
field is a number, you shouldn't be quoting the value you're comparing to, here:
WHERE id = '" . $ident . "'";
Just do this:
WHERE id = " . $ident;
One often overlooked test to to have your script echo out the actual query that's being run, and then take that query string and run it directly against the database server - in your case, in phpMyAdmin against your MySQL server.
Upvotes: 0
Reputation: 3335
You should put the field names like name, website and so on in this quotation marks: ` And you should only use one space between the words and maybe add a space before the WHERE.
Upvotes: 2