I have been trying to post orderid,extension id ... with javascript POST method but its always returning false even if the SQL query is true. Demo data:
Javascript
var order_id = "1232";
var extension_id = "12";
var email = "flencsso@gmail.com";
var dom = "www.youtube.com";
$.post(
"checkdata.php",
{
order_id: order_id,
extension_id: extension_id,
email: email,
dom:dom
},
function (data, status) {
//console.log("Data: " + JSON.parse(data) + "\nStatus: " + status);
console.log(data + "status:" + status);
}
);
this data is exist in the table 'osmo'. Also i have declared all the columns as VARCHAR. Please suggest whats wrong i am doing with the query.
PHP
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!empty($_POST['order_id']) && !empty($_POST['extension_id']) && !empty($_POST['email']) && !empty($_POST['dom'])) {
//store in variables
$order_id = $_POST['order_id'];
$extension_id = $_POST['extension_id'];
$email = $_POST['email'];
$dom = $_POST['dom'];
//server config
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "foroc";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//sql query
$sql = "SELECT *
FROM ocorders
WHERE order_id='$order_id'
AND extension_id='$extension_id'
AND email='$email'
AND order_status='Complete'
AND dom='$dom'
";
$result = mysqli_query($conn, $sql);
//check if sql query is returning true or false
if (mysqli_num_rows($result) > 0) {
// output data of each row
while ($row = mysqli_fetch_assoc($result)) {
print json_encode("true");
}
} else {
print json_encode("false");
}
//close connection
$conn->close();
}
}