Hey,
How you been, I was trying to work with json data in php and mysql using ajax
Something strange is happening, when i comment the below line -
// $row=mysqli_fetch_array($result,MYSQLI_ASSOC);
<?php
session_start();
$message=array();
include('database.php');
$sql="SELECT * from ratings ORDER BYRAND() LIMIT 1";
$result = mysqli_query($conn,$sql);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
//$message["image"]=$row['image'];
$message["message"]='hello';
//$message["message2"]='hello2';
header('content-type: application/json');
echo json_encode($message);
I get the message in my console.log using ajax but when i uncomment this $row = mysqli_fetch_array.... i get nothing in my console log
what is wrong in here ? I am on xampp 3.2.2 incase and there is no db error, also pasting my databse.php code just incase you wish to see
<?php
$DBServer = 'localhost';
$DBUser = 'root';
$DBPass = '';
$DBName = 'starrating';
$conn = new mysqli($DBServer,$DBUser,$DBPass,$DBName);
if($conn->connect_error){
// echo $conn->connect_error;
die('Connect Error: ' . $mysqli->connect_error);
}
function cleanup($data){
return mysql_real_escape_string(trim(htmlentities(strip_tags($data))));
}
incase you want to see my jquery code, but i know its not related to this
//ajax call
$.ajax({
type:"POST",
url:"server.php",
datatype:"json",
success: function(data){
console.log(data);
}
Also attaching both the files
// $row=mysqli_fetch_array($result,MYSQLI_ASSOC);
database.php
index.html
server.php