Jump to content

mysqli_fetch_array line blocking every code below it

Recommended Posts

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);


$sql="SELECT * from ratings ORDER BYRAND() LIMIT 1";
$result = mysqli_query($conn,$sql);


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
$DBServer = 'localhost';
$DBUser = 'root';
$DBPass = '';
$DBName = 'starrating';

$conn = new mysqli($DBServer,$DBUser,$DBPass,$DBName);
    // 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
                   success: function(data){

Also attaching both the files


// $row=mysqli_fetch_array($result,MYSQLI_ASSOC);




Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.