I have two links, Delete and View. Delete is working perfectly. I am getting the issue on view link. I have to display specific records after clicked on view link.If you notice that delete anchor tag I wrote href='delete.php?function=delete&del_id=$id'
. It's calling the delete.php file and deleting a specific record. I want to know about how to write in view anchor tag to display records? Please check below image.I want to clicked on view and display the records in text fields.PHP file added. Please check my ajax code. It is also not working. Ajax code is not working here. I have to display the output in the text field.If i write directly $id=2 then it is display records in alert. Hope you guys can understand now.Would you help me in this?
//delete.php
function view($conn) {
$id=$_GET['view_id'];
$admin_view="SELECT * from view_table WHERE Id=$id";
$result = $conn->query($admin_view);
if (isset($result->num_rows) > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$parent_name=$row['Name'];
$parent_email=$row['Email'];
$admin_mobile=$row['Mobile_no'];
}
}
}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<a href='delete.php?function=delete&del_id=$id' >Delete</a>
<a href='#Popup' onClick='a_onClick(<?php $id?>)' class='btn-view'>View</a>
<form action="#" method="post">
<input type="text" name="Name" placeholder="username" value="<?php echo $parent_name;?>" >
<input type="email" name="email" placeholder="email" value="<?php echo $parent_email;?>" >
<input type="text" name="Mobile_no" placeholder="Mobile no" value="<?php echo $admin_mobile;?>" >
<a href="#" class="cancel">Cancel</a> <span class="close"></div>
</form>
<script>
function a_onClick(id) {
var id = id;
var Name=$('#name').val();
$.ajax({ //create an ajax request to load_page.php
type: "GET",
url: "delete.php?function=view&view_id=id",
data:'Name='+Name,
dataType: "html", //expect html to be returned
success: function(response) {
// $("#responsecontainer").html(response);
alert(response);
}
});
}
</script>
you need to change some changes
<a href='#Popup' onClick='a_onClick(<?= $id ?>)' class='btn-view'>View</a>
<script>
function a_onClick(id) {
var id = id;
$.ajax({ //create an ajax request to load_page.php
type: "GET",
url: "delete.php?function=view&view_id=id",
data:'Name='+Name,
dataType: "html", //expect html to be returned
success: function(response) {
// $("#responsecontainer").html(response);
alert(response);
}
});
}
</script>
hope its help you