我想知道为什么这段代码对我不起作用。我想将来自数据库的值附加到此提交按钮的输入字段中,因为我想将其发送回数据库中的另一个表。谢谢!
</div>
<form>
<input type="input" value="'+ jobpost.jobID+'" id="jobID"/>
<br>
<button type="submit" id="submit3" name="submit3"
onclick="myFunctionjobStatus();">Submit</button></form></div>
我正在使用以下ajax帖子将数据发送到我的php文件中,以输入数据库。请参见下面。
function myFunctionjobStatus() {
var jobID = document.getElementById("jobID").value;
//AJAX code to submit form.
$.ajax({
type: "POST",
url: "http://localhost:8888/EduSubOct/jobstatus.php",
data: { userEmail: localStorage.getItem("email"), jobID:
jobID},
cache: false,
success: function(html) {
alert("Request Sent");
}
});
}
php文件-
<?php
// Selecting Database
include_once 'dbh.php';
/Here we fetch the data from the URL that was passed from our HTML
form
$userEmail = $_POST['userEmail'];
$jobID = $_POST['jobID'];
$sql = "INSERT INTO jobStatus (email, jobID) VALUES
('$userEmail','$jobID');";
mysqli_query($conn, $sql);
?>