Php 使用POST和jQuery发送html表单时出错

Php 使用POST和jQuery发送html表单时出错,php,jquery,html,ajax,Php,Jquery,Html,Ajax,我有以下表格: <form id="ereserva" action="index.php" method="post"> <fieldset> <label for="id">ID</label> <input type="id" name="ei" id="eid" readonly class="id text ui-widget-content ui-corner-all"> &

我有以下表格:

<form id="ereserva"  action="index.php" method="post">
    <fieldset>
        <label for="id">ID</label>
      <input type="id" name="ei" id="eid" readonly class="id text ui-widget-content ui-corner-all">
      <label for="name">Nombre</label>
      <input type="text" name="en" id="ename"  class="name text ui-widget-content ui-corner-all">
     </fieldset>
    <input type="submit" tabindex="-1">   
</form>
到执行此操作的php文件:

<?php
include_once('connection.php');
$id = $_POST['ei'];        
$name = $_POST['en'];

if($con->query("UPDATE reserves SET nom='".$name."' WHERE ID ='".$id."';")=== TRUE)
         printf("alert('success');");
        else
        printf("alert('fail');");
?>

但是变量
id
从表单名
ei
到达POST,这是一个明确填充的表单字段,因此我仍然看不清楚。

500
表示服务器上有错误:

if($con->query("UPDATE reserves SET nom='".$name."' WHERE ID =".$id))
//                                                        ^^^^^^^^^
    printf("alert('success');");
else
    printf("alert('fail');");
您在
WHERE
之前的查询中添加了额外的
逗号


另外,猜测
ID
integer
,因此不需要
引号

我猜错误来自另一个脚本,因为您将
$\u POST['ei']
分配给
ID
,这意味着定义了
ID
。如果未定义
$\u POST['ei']
,则错误为
未定义索引ei

此外,您应该清理数据,或者使用准备好的语句来防止数据丢失。例如:

$id = intval($id);
$name = mysql_real_escape_string($name);

检查您的web服务器错误日志。一个错误是
,其中
$con->query(“更新保留集nom=”“$name.”,其中ID=”“$ID.”;”)
使用
$con->query(“更新保留集nom=”“$name.”“其中ID=”“$ID.”;”)
谢谢,我已经修复了,但错误仍然存在。可能还有别的事情。我将再次尝试调查Morethance@Tushar,我修复了引号,尽管问题仍然存在。就好像没有从表单中发送
id
properly@telex-wap尝试删除
==TRUE
,这是不必要的,可能会导致错误,不确定。最后,您关于引号的提示使我进一步探索了查询,并看到另一个不属于那里的错误符号(我在这里复制粘贴代码时错过了它。修复后,一切都很好!感谢您的建议。我首先了解后处理是如何工作的,因为我现在已经开始工作了,表单也工作得很好,下一步就是按照您所说的清理数据。此代码不是用于生产,只是一个测试。
if($con->query("UPDATE reserves SET nom='".$name."' WHERE ID =".$id))
//                                                        ^^^^^^^^^
    printf("alert('success');");
else
    printf("alert('fail');");
$id = intval($id);
$name = mysql_real_escape_string($name);