ersaurabh101 Posted February 23, 2017 Share Posted February 23, 2017 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 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted February 23, 2017 Share Posted February 23, 2017 What is “ORDER BYRAND()” supposed to mean? Otherwise, the usual problems: You have no error checks whatsoever. No, mysqli doesn't do that for you, unless you explicitly ask for error reporting. Your PHP error reporting also seems to be off. You should be seeing a big fatal error in your log. The Ajax script is unable to handle errors, which is a problem. Quote Link to comment Share on other sites More sharing options...
ersaurabh101 Posted February 23, 2017 Author Share Posted February 23, 2017 (edited) ohh, it should be ORDER BY RAND() , thanks worked , how to switch on php error reporting ? Edited February 23, 2017 by ersaurabh101 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 23, 2017 Share Posted February 23, 2017 How to turn on error reporting? You could reference the manual which is great for learning about stuff. Or you could look at my signature. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.