为什么数据没有通过javascript传递到php

为什么数据没有通过javascript传递到php,javascript,php,Javascript,Php,我使用以下表格: <form id="dataForm" method="post"> <h2 id="formheader"> Update Product Description</h2> <div> <label>Product Name:</label> <input class="inputForm" id="orginalName" type="text" name="N

我使用以下表格:

<form id="dataForm" method="post">
  <h2 id="formheader"> Update Product Description</h2>
    <div>
      <label>Product Name:</label>
      <input class="inputForm" id="orginalName" type="text" name="Name">
    </div>
    <div>
      <label>New Description:</label>
      <input class="inputForm" id="newDescription" type="text" name="newDescription">
    </div>
    <div id="theSubmit">
      <button id="editDescription">Submit</button>
    </div>
  </form>
然后,当我使用下面的java脚本时,数据没有通过,我看不出为什么,因为我有一个类似的函数和表单,JavaScript工作得很好,有人能看到为什么数据没有通过吗

function editDescription(){
    xmlhttp = new XMLHttpRequest();
    var name = document.getElementById("orginalName");
    var Description = document.getElementById("newDescription");

    var data_seen = false;
        // this is a flag to record whether any data has been seen. Used in the guard ofthe alert statement.
    if (name.value !="" && Description.value !="" ){
        data_seen = true;
        xmlhttp.open("POST","editDescription.PHP",true);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send("Name=" + name.value + "&Description=" + Description.value);
    }
    if (!data_seen) {
        alert("please enter some data");
    }
   }

submitButton = document.getElementById("editDescription");
submitButton.addEventListener("click", editDescription);

您正在发布到
editDescription.PHP
而不是
editProductDes.PHP

更改以下内容:

xmlhttp.open("POST","editProductDes.php",true);
您在文章中发送的数据的名称也不同于您在PHP代码中预期的名称(
Description
,而不是
newDescription
)-更改:

xmlhttp.send("Name=" + name.value + "&newDescription=" + Description.value);

你有什么错误?我在控制台中没有得到任何错误或任何东西,当javascript运行到php页面以运行sql时,数据没有通过。首先将editDescription.php更改为editDescription.php,并在php文件$Description=$\u POST['newDescription'];to$Description=$\u POST['Description']。由于参数名错误,您将null值传递给SQL。它会返回空值错误吗?注入攻击很常见,真的很常见。如果
$Name
持有一个类似
x'的值或一个类似“%”的P_Name,则最好保护自己不受这些影响--
,这将使where子句看起来像
where P_NAME='x'或P_NAME像“%”
,并更新整个表您的
javascript
函数正在运行或默认
form
提交??是的,很抱歉,这就是我更改文件名的地方,您是正确的,但是这并没有帮助解决问题
xmlhttp.send("Name=" + name.value + "&newDescription=" + Description.value);