简体   繁体   中英

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. For example, When user clicks the button, this will update value inside database based on the id of where the button is located. 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 -

 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)

PHP variables are case-sensitive you know?

$jobiD = $_POST['jobID'];

$jobiD should be $jobID as you used it on your query string:

$sql =  "UPDATE jobPost SET emailTeacher='$userEmail' WHERE jobID= ('".$jobID."');";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM