简体   繁体   English

PHP脚本不更新MySQL行

[英]php script not updating mysql row

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. 以下是我拥有的当前脚本,该脚本从ajax调用获取值。 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? 我对此仍然很陌生,有人可以解释为什么它不起作用吗?

您应该在该引号中添加字段名称,例如名称,网站等:`并且您应该仅在单词之间使用一个空格,并且可能在WHERE之前添加一个空格。

您需要在“ where”之前添加空间

If your id field is a number, you shouldn't be quoting the value you're comparing to, here: 如果您的id字段是数字,则不应在此处引用要比较的值:

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. 一个经常被忽略的测试,使您的脚本回显正在运行的实际查询,然后获取该查询字符串并直接在数据库服务器上运行它(在您的情况下,在MySQL服务器上的phpMyAdmin中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM