Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given
You have:
mysqli_fetch_array($query)
Should be:
mysqli_fetch_array($result)
Also in line 3 you have:
if($query === FALSE) { die(mysql_error()); }
Should be rather:
if ($result === FALSE) { die(mysql_error()); }
error mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given
Problem
You are missing how to pass the argument to mysqli_fetch_array()
.
Solution
Therefore, this line:
if(mysqli_query($cons, $result)) {
should be
if($res = mysqli_query($cons, $result)) { // assign the return value of mysqli_query to $res
(FWIW, I'd go with $res = mysqli_query($cons, $result);
then do if($res) {
.)
And then do
while($row = mysqli_fetch_array($res)) // pass $res to mysqli_fetch_array instead of the query itself
Why?
You were giving to mysqli_fetch_array()
- as an argument - the string
that contains your query. That's not how it works. You should pass the return value of mysqli_query()
instead. Therefore, you could also write: while($row = mysqli_fetch_array(mysqli_query($cons, $result))) {}
(but it's not adviced, it is just to show you how it works).
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result when I have 2 parameters
Use $row=mysqli_fetch_array($result);
in place of $row=mysqli_fetch_array($query);
As mysqli_fetch_array() function fetches a result row as an associative array and you were passing $query which is of type string. So, its throwing error.
How to solve mysqli_fetch_array() expects parameter 1 to be mysqli_result,string in php
In this code you did not execute the queries so you cannot fetch.
Try this approach:
<?php
if(isset($_GET['id'], $_GET['twd'])){
/*Importing our db connection script*/
require_once('dbConnect.php');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sql = sprintf("SELECT MAX(id) as MaxId FROM work_details WHERE twd = '%s'",
mysqli_real_escape_string($_GET['twd']));
if ($result = mysqli_query($con, $sql)) {
/* fetch associative array */
if ($row = mysqli_fetch_row($result)) {
if($row[0] === $_GET['id']){
$sql = sprintf("DELETE FROM work_details WHERE id='%s';",
mysqli_real_escape_string($_GET['id']));
if ($result = mysqli_query($con, $sql)) {
echo 'success';
}else{
echo 'failed';
}
}
}
/* free result set */
mysqli_free_result($result);
}
/* close connection */
mysqli_close($con);
}
?>
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in
mysqli_fetch_array()
's 1st parameter must be a result of a query. What you are doing is you are passing the connection (which doesn't make sense) and the query command itself.
Read the doc here: http://php.net/manual/en/mysqli-result.fetch-array.php
To fix this, execute the query first, then store the result to a variable then later fetch that variable.
$sql = "select * from privinsi";
$result = mysqli_query($connection,$sql);
while($r = mysqli_fetch_array($result))
{
// your code here
}
mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given error
remove apostrophe around $result
. This mysqli_fetch_array('$result')
should be mysqli_fetch_array($result)
Note the difference:
'$result'
is a string (single apostrophe)
$result
is a resource returned by mysqli_query
Related Topics
Codeigniter Call to a Member Function Num Rows on Boolean
404 Not Found When Passing Variable to Route in Laravel
How to Remove Accents from Characters in a PHP String
Comparing Two Dates in a SQL Request
Retrieve MySQL Value from PHP for Radio Buttons
Mongodb Updating Fields in Nested Array
Remove Useless Zero Digits from Decimals in PHP
(Php, Mysql) Result Could Not Be Converted to String
Windows 10 Docker:/Usr/Bin/Env: 'Php\R': No Such File or Directory
404 Not Found; Apache Server Can't Load Simple PHP File
Generating a Truly Unique Order Id in PHP
Codeigniter - Call to a Member Function Result() on Boolean In
Php Session Lost After Redirect
Getting Date Format M-D-Y H:I:S.U from Milliseconds
How to Get Comma Separated Values from a Table in Laravel