Hi, I am looking around this all day but cant find out a way.
Basically I have a html page with Jquery function that send data to a php file to retrieve data from a database.
Retrieving data to the html page works fine.
What I am trying to do is run a comparison between the value that is fetched from database and a set limit.
This is what I have so far.
Html file
and PHP file.
Any help would be appreciated.
Also if you know a better way let me know.
Basically I have a html page with Jquery function that send data to a php file to retrieve data from a database.
Retrieving data to the html page works fine.
What I am trying to do is run a comparison between the value that is fetched from database and a set limit.
This is what I have so far.
Html file
Code:
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>
<script>
function check(str1) {
if (str1 == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
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 (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","test.php?q="+str1,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form name= "myForm">
Core Arm number:</br>
<input type="number" id="Arm" name="Arm" onchange= "check(this.value)" >
</br>
</form>
<br>
</div>
<div id="txtHint"><b>info will be listed here...</b></div>
</body>
</html>
Code:
<?php
$q = intval($_GET['q']);
echo $q."<br>";
$servername = "localhost";
$username = "Admin";
$password = "29N7Lp8SA6yWUaGM";
$dbname = "coredb";
$tbname= "ArmTable";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error()."<br>");
}
echo "Connected successfully <br>";
mysqli_select_db($conn,$dbname);
$row = mysqli_fetch_array(mysqli_query($conn, "SELECT SleCount FROM ".$tbname." WHERE CoreArm = '123456'"));
// This is in the PHP file and sends a Javascript alert to the client
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
if ($row['SleCount']>=2)
echo "Exeeded Count ".$row['SleCount']." Segregate arm for Sleeve change. <script type='text/javascript'> alert('segregate');</script> <br><br><br>";
mysqli_close($conn);
?>
Also if you know a better way let me know.
Comment