I can't seems to retrieve the PHP POST value from the form. The inputs value are being retrieved from Ajax and being inserted into input form below. However, the test on form submission can't retrieve value from the input. May I know what is the issue and how to solve it? Thanks in advance.
UpdateProfile.php
<?php
session_start();
include("dbcon.php");
if(isset($_POST['updateProfile']))
{
$profileCode=$_POST['profileCode'];
$profileName=$_POST['profileName'];
$profileDesc=$_POST['profileDesc'];
echo "<script>alert('".$profileCode."')</script>";
$find_user="select * from profile where profileCode='$profileCode'";
$statement = $dbcon->prepare($find_user);
$statement->execute();
if($row = $statement->fetch())
{
echo "<script>alert('".$profileCode."')</script>";
}
else
{
echo "<script>alert('Failed to update profile!')</script>";
}
}
?>
<script>
function editBtn(profileCode) {
$.ajax({
type:"POST",
url: "test.php",
dataType: "html",
data: {profileCode:profileCode},
success: function(data){
$('#profileCode').val(data.split(",")[0]);
$('#profileName').val(data.split(",")[1]);
$('#profileDesc').val(data.split(",")[2]);
event.preventDefault();
}
});}
</script>
<?php
$username = $_SESSION["username"];
$query = "SELECT * FROM profile WHERE username='$username'";
$statement = $dbcon->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<i class="ti-pencil" onclick="editBtn('<?php echo $row['profileCode']; ?>')"></i>
<?php } ?>
<form role="form" method="post" action="manageprofile.php">
<label>Profile Code</label>
<input type="text" class="form-control border-input" id="profileCode" name="profileCode" value="" disabled>
<label>Profile Name</label>
<input type="text" class="form-control border-input" id="profileName" name="profileName" value="" placeholder="Profile Name" required>
<label>Profile Description</label>
<textarea rows="5" class="form-control border-input" placeholder="About you" id="profileDesc" name="profileDesc" value=""></textarea>
</form>
test.php
<?php
include("dbcon.php");
$courseCode = $_POST['profileCode'];
$query = " SELECT * FROM profile WHERE profileCode='$profileCode' ";
$statement = $dbcon->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
echo $row['profileCode'].",".$row['profileName'].",".$row['profileDesc'];
} ?>
Image: Post return no value in alert
Error Code : line 7 ($profileCode=$_POST['profileCode'];) //after click on submit
test.phppage which is where the AJAX is sending the POSTed data , and/or the manageprofile.php page which is where the form sends the posted data....data: {profileCode:profileCode}Where isprofileCodeset?