Index.php
This is part of my Index.php code, I cannot pass data to the file “action/viewupdate.php” using ajax.
<tr>
<td><?php echo $row['word'] ?></td>
<td><?php echo $row['comment'] ?></td>
<td><?php echo $row['viewno'] ?>
<Span id="view_update<?php echo $count; ?>" style="display:none;font-weight:1000;color:green;font-size:12px"></Span>
</td>
<form action="" method="post" id="viewupdate<?php echo $count; ?>">
<td><input type='button' name='viewupdate' value='Update' data-action="viewupdate<?php echo $count; ?>" class="button" /></td>
<input type="hidden" id="userselectchannel<?php echo $count; ?>" name="userselectchannel<?php echo $count; ?>" value="<?php echo $row['videoline'] ?>">
<input type="hidden" id="updateno<?php echo $count; ?>" name="updateno<?php echo $count; ?>" value="">
<td style="display:none" id="saveupdateclm<?php echo $count; ?>"><input id="saveupdatebtn<?php echo $count; ?>" type='button' name='saveupdate<?php echo $count; ?>' value='Save**strong text**' data-action="saveupdate<?php echo $count; ?>" class="confirmbutton" /></td>
</form>
</tr>
<script>
$('#saveupdatebtn<?php echo $count; ?>').click(function() {
var updateno1 = $('#updateno<?php echo $count; ?>').val();
var userselectchannel1 = $('#userselectchannel<?php echo $count; ?>').val();
var username1 = "<?php echo $_SESSION['nick_name']; ?>";
/* alert(updateno + "n" + userselectchannel + "n" + username); */
$.ajax({
url: 'action/viewupdate.php',
type: 'POST',
data: {
"updateno": updateno1,
"userselectchannel": userselectchannel1,
"username": username1
},
cache: false,
success: function(msg) {
console.log(data);
var x = document.getElementById("errorpopup2");
x.innerHTML = "<div style='color:#21ff21;'>Video <?php echo $count ?>Views update successfully</div>";
x.className = "show";
setTimeout(function() {
x.className = x.className.replace("show", "");
}, 3000);
$("#saveupdatebtn<?php echo $count; ?>").attr("disabled", "disabled");
$('#saveupdatebtn<?php echo $count; ?>').css('cursor', 'not-allowed');
return false;
},
error: function(msg) {
var x = document.getElementById("errorpopup2");
x.innerHTML = "Unknown Error Occured";
x.className = "show";
setTimeout(function() {
x.className = x.className.replace("show", "");
}, 3000);
return false;
}
});
});
Viewupdate.php
<?php
include_once "../../system/connect.php";
$updateno=$_POST['updateno'];
$userselectchannel=$_POST['userselectchannel'];
$username=$_POST['username'];
$time = date('Y-m-d H:i:s');
$updatetitle = $updateno;
$sql = "INSERT INTO `pagecontent_update`(`update-user`, `update-time`, `update-info`)
VALUES ('$username','$time','$updatetitle')";
if (mysqli_query($link, $sql)) {
echo json_encode(array("statusCode"=>200));
}
else {
echo json_encode(array("statusCode"=>201));
}
?>
PhpMyAdmin Screenshot
https://drive.google.com/file/d/1NcTYZNWhFMSQZMCZiNrTcfX-MPN4UGnT/view?usp=sharing
As the picture shown, data cannot pass to Viewupdate.php using ajax. As I wish that when user press the submit button, the data will stored into the database without refresh. Thx a lot.
If you need more information, please contact me at any time.