Hi, I got this error. Please help.

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY '".$crieria."' ASC);

$array1 = array();

while($row = mysqli_fetch_array($result_1)){
array_push($array1, "$row[0]->$criteria", "$row[5]->$criteria" , "$row[10]->$criteria");
}

mysqli_query returns false on failure, indicating something is wrong with your query. See the sticky thread at the top of the PHP forum to find out how you can check for errors (most likely because $criteria is misspelled).

commented: Yes +6

check your spelling is correct or not for '$crieria' near to ORDER BY

mysqli_query returns false on failure, indicating something is wrong with your query. See the sticky thread at the top of the PHP forum to find out how you can check for errors (most likely because $criteria is misspelled).

Sorry pritaeas.. I haven't see your post.

I typed myself wrongly, but in my code i checked and there is no misspell.

@Karthik: No need to be sorry. We saw the same thing, and were probably typing at the same time.

@Jiaxin: See the sticky thread first. It tells you how to trap and find errors.

Replace your query

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY '".$crieria."' ASC);

with

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY $crieria ASC");

I replaced it but still have the same error.

just echo out the query as

echo "SELECT $criteria FROM table ORDER BY $crieria ASC";

before this line

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY $crieria ASC");

copy the printed query and execute it in the SQL section of your phpmyadmin and see the result. it will tell the error if you have error in your query

SELECT $criteria Why dollar sign before 'criteria' after 'SELECT' ?

Only do that if you want to replace it with a variable. If you think it is wrong, replace it with a *

try:

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY $crieria ASC") or die( mysqli_error($link) );

try:

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY $crieria ASC") or die( mysqli_error($link) );

Always let PHP display errors for you in development. Another way described in PHP Manual is:

/* Create table doesn't return a resultset */
if (mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
    printf("Table myCity successfully created.\n");
}

/* Select queries return a resultset */
if ($result = mysqli_query($link, "SELECT Name FROM City LIMIT 10")) {
    printf("Select returned %d rows.\n", mysqli_num_rows($result));

    /* free result set */
    mysqli_free_result($result);
}

because i pass in the user input at the $criteria

i have already echo out this
echo "SELECT $criteria FROM table ORDER BY $crieria ASC";

but then the result shown are only:
SELECT FROM criteria ORDER BY ASC

and not the real data from database. what can i do to make it echo out all the data in ASC?

i have already echo out this
echo "SELECT $criteria FROM table ORDER BY $crieria ASC";

but then the result shown are only:
SELECT FROM criteria ORDER BY ASC

and not the real data from database. what can i do to make it echo out all the data in ASC?

Then problem is not in query. Problem is in your input $criteria. Check your input or post your all codes.

<?php include('server.php');

// fetch the record to be updated
if (isset($_GET['edit'])){
    $Id_alat = $_GET['edit'];
    $edit_state = true;
    $rec = mysqli_query($db, "SELECT * FROM alat WHERE Id_alat=$Id_alat");
    $record = mysqli_fetch_array($rec);  -- > its line 8 (wrong code!!)
    $timestamp = $record['timestamp'];
    $klamp = $record['klamp'];
    $Id_alat = $record['Id_alat'];

}

?>

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\php_crud\index.php on line 8

please solve code above it?

My Code:
<?php
include("validation.php");
include("conection.php");
if(isset($_POST["button"]))

$pwde = md5($_POST[password]);

$sql="INSERT INTO administrator (adminid, adminname, password, address, contactno)
VALUES
('$_POST[adminid]','$_POST[adminname]','$pwde','$_POST[address]','$_POST[contactno]')";

if (!mysql_query($sql,$con))

die('Error: ' . mysql_error());

else

  echo "1 record Inserted Successfully...";

$result = mysql_query("SELECT * FROM administrator");
while($row1 = mysql_fetch_array($result))

$adminid = $row1["adminid"]+1;
}

if(isset($_POST["button2"]))

$pwde = md5($_POST[password]);

mysql_query("UPDATE administrator SET adminname='$_POST[adminname]', address='$_POST[address]', contactno='$_POST[contactno]'
WHERE adminid = '$_POST[adminid]'");
echo "Record updated successfully";

if($_GET[view] == "administrator")

$result = mysql_query("SELECT * FROM administrator where adminid='$_GET[slid]'");
while($row1 = mysql_fetch_array($result))

$adminid = $row1["adminid"];
$password = $row1["password"];
$adminname = $row1["adminname"];
$address = $row1["address"];

$contact = $row1["contactno"];

?>

After execution got below warning:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

Please Support....

commented: Dont hijack a 6 year old thread. Start your own. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.