I don't know why, but the variable $idCount
does not increment, it just remains at 1001. I would like to loop through and create nine hyperlinks which all delete a specific record from the database.
<script>
function passValue() {
var js_var = document.getElementById("link").getAttribute("value");
alert(js_var);
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","data.php?q="+js_var,true);
xmlhttp.send();
}
</script>
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
$dbname = "test";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM customers";
$rs = mysqli_query($conn, $sql)
or die(mysqli_error($conn));
$idCount = 1001;
while($rc = mysqli_fetch_assoc($rs)) {
echo $idCount . '<tr><td><a id="link" href="javascript:passValue()" value="'.$idCount.'")>Delete Record</a></td><td>' . $rc["custID"] . '</td><td>' . $rc["custName"] . '</td><td>' . $rc["custPassword"] . '</td><td>' . $rc["custGender"] . '</tr>';
$idCount++;
};
?>