我必须创建文件,其中一个是index.php,另一个是survey-result.php。
Index.php 包含一项调查和一个按钮,单击该按钮应将调查名称和结果发布到 Survey-result.php。然后,survey-result.php 应建立 mysql 连接,并使用索引的结果更新数据库,找到正确的调查。
网址示例:index.php?id=528E6B678ECE0
Id是一个调查名称,存在于mysql数据库中。
问题:两个php文件之间没有联系。如果我在结果和调查名称中使用手动数据运行调查结果,那么它将更新我的数据库。
有什么想法吗? :D
<input type='button' value='Create User' onclick='updateSurvey()' />;
function updateSurvey()
{
$.ajax(
{
url: 'handlers/survey-result.php',
data:
{
action: 'action',
surveyname: <?php echo $_GET["id"]; ?>,
result: 'Test Result',
type: 'post',
success: function(output)
{
alert("Survey result updated");
}
});
}
</script>
handlers/survey-result.php
<?php
if(isset($_POST['action']) )
{
include("include/dbConnect.php");
$strSQL = " UPDATE surveys
SET result= . $_POST['result'] .
WHERE surveyname= . $_POST['surveyname']";
// The SQL statement is executed
mysql_query($strSQL) or die (mysql_error());
// Close the database connection
mysql_close();
}
?>
最佳答案
尝试使用“$.post()”而不是“$.ajax()”。这将有助于正确格式化:
关于php - Post 和 ajax/php 不会一起对话吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20200364/