[英]MYSQL - PHP - Update value in database by using variable passed from submit button
I want to know if it possible to pass a value from database as seen below into my php file and UPDATE the corresponding row value based on this passed paramater. 我想知道是否有可能从数据库中传递一个值(如下所示)到我的php文件中,并根据传递的参数更新相应的行值。 For example, When user clicks the button, this will update value inside database based on the id of where the button is located. 例如,当用户单击按钮时,这将基于按钮所在的ID更新数据库内部的值。 Thank you. 谢谢。
<?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 = "UPDATE jobPost SET emailTeacher='$userEmail' WHERE jobID= ('".$jobID."');";
mysqli_query($conn, $sql);
?>
AJAX - AJAX-
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");
}
});
}
See attached iamge of code -codeblock wont work for me) 请参阅随附的代码iamge -codeblock无法为我工作)
PHP variables are case-sensitive you know? PHP变量区分大小写,您知道吗?
$jobiD = $_POST['jobID'];
$jobiD should be $jobID as you used it on your query string: $作业ID应该是$作业ID,你用它在你的查询字符串:
$sql = "UPDATE jobPost SET emailTeacher='$userEmail' WHERE jobID= ('".$jobID."');";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.