This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 8 years ago.
I have a piece of PHP code I am using to grab the 20 next messages in a database.
<?php
$user_email_msg = "bob#gmail.com";
$msg_email = "sam#gmail.com";
$start_query_msg = 1;
$end_query_msg = $start_query_msg-20;
$user_link_msg = mysqli_connect("localhost", "root", "admin", $user_email_msg);
$query_msg = "SELECT * FROM " . $msg_email . " WHERE id BETWEEN " . (string)$end_query_msg . " AND " . (string)$start_query_msg;
$result_msg = mysqli_query($user_link_msg, $query_msg);
$row_msg = mysqli_fetch_all($result_msg, MYSQLI_NUM);
$next_20 = $row_msg[0];
print_r($next_20);
?>
When I run this code I get this error message:
"Warning: mysqli_fetch_all() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\jayden\messages.php on line 10"
I am so lost here, because I can't see any way that $result_msg can be returning a boolean value.
How can I fix the issue?
I may be wrong, but most likely your fourth parameter to mysqli_connect is not an email address but should rather be the database name
echo the variable $query_msg and run the query in phpmyadmin or any favorite application. The error is about mistake in sql query check that now.
print the query and check if the query is ok.
print_r($query_msg);
this problem occurs when your query is not right.
Related
This question already has answers here:
mysqli_real_escape_string() expects exactly 2 parameters, 1 given
(5 answers)
Closed 5 years ago.
I have a page from a website that I took over a few years back. I am a novice on php and are more into Wordpress. Now the page is starting having problems and I get the above errors in the given lines.
This is the code:
1. $db = mysqli_connect("localhost", "vrvtnl_data", "eric") or die
("fout1");
2. //mysqli_select_db("vrvtnl_data",$db) or die ("fout2");
3. function test($nummer,$week){
4. $sql = 'SELECT * FROM `vakantie` WHERE `tandarts` =' .
5. $nummer . '';
6. $result = mysqli_real_query($sql);
7. $test = mysqli_use_result($result, 0, "". $week ."");
8. return $test; }
Can somebody help me, as said I am a novice with php, so detailed help ia appreciated.
You passing only one parameter (query), but you must pass two parameters (connection link and query).
bool mysqli_real_query ( mysqli $link , string $query )
Parameters:
link
Procedural style only: A link identifier returned by mysqli_connect()
or mysqli_init()
query
The query, as a string.
http://php.net/manual/en/mysqli.real-query.php
But in your situation you need mysqli_query.
Your code should look like:
$db = mysqli_connect("localhost", "vrvtnl_data", "eric") or die ("fout1");
function test($nummer, $week) {
global $db;
$sql = "SELECT * FROM `vakantie` WHERE `tandarts` = '$nummer'";
$result = mysqli_query($db, $sql);
return $result ? mysqli_fetch_assoc($result) : [];
}
This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 5 years ago.
I have a mysqli query that wont execute and I would like to display information about why that's happening. Im just fooling around with this example but I imagine something like this:
$myQuery= $mysqli->query("UPDATE table SET id = 1 WHERE id = 3");
if(!$myQuery) //If query couldnt be executed
{
echo $mysqli->error; //Display information about why wasnt executed (eg. Error: couldnt find table)
}
try using
// Perform a query, check for error
if (!mysqli_query($con,"UPDATE table SET id = 1 WHERE id = 3"))
{
echo("Error description: " . mysqli_error($con));
}
mysqli_close($con);
This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
(31 answers)
Closed 6 years ago.
I have a line of code in my php that reads:
$sel_venue = "SELECT 'char_type' FROM 'character_type_allowed' WHERE status='Open'";
$run_venue = mysqli_query($con,$sel_venue);
while ($row = mysqli_fetch_array($run_venue))
if ($row['char_type'] == 'Mortal')
{ print ("<li><a href='http://houston-by-night.com/sheets/create/mortal.php'>Create Mortal</a></li>"); }
The link associated with this does nothing. Zero interaction beyond acting likeit wants to expand. My error log produces this: Why is it asking for this?
[08-Aug-2016 23:28:41 America/New_York] PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/houchat/public_html/incl/creation.php on line 8
You can't use ' as ticks for field/tablenames.
Your query is producing an error. You can see the error with mysqli_error($con).
Please see the corrected code below
$sel_venue = "SELECT `char_type` FROM `character_type_allowed` WHERE status='Open'";
$run_venue = mysqli_query($con,$sel_venue) or die(mysqli_error($con));
while ($row = mysqli_fetch_array($run_venue)) {
if ($row['char_type'] === 'Mortal') {
print ("<li><a href='http://houston-by-night.com/sheets/create/mortal.php'>Create Mortal</a></li>");
}
}
Your query failed, so $run_venue is the boolean false instead of what you expect. You should check for errors before you use any query result. Do this:
$run_venue = mysqli_query(...);
if(!$run_venue) die(mysqli_error($con));
... //<- we get here if the query succeeded
You will see the error. The problem is that your SQL statement wraps the table name between single quotes 'character_type_allowed', instead of backticks (backtick is above the tab key on my keyboard)
This question already has an answer here:
MysQl error : Invalid parameter number
(1 answer)
Closed 8 years ago.
Its probley something small but i been looking at this for ages and still cant get it to work at all im getting two errors
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number in
the code i have is this:
public function getdata ($tran_id)
{
$sql = "SELECT tran_id, seller_user_name, user_name_buyer
FROM trade_transaction, feedback Where feedback.feedback_username = trade.user_name_of_buyer
AND user_name_of_buyer = :user_name_buyer ";
$sth = $this->db->prepare($sql);
$sth->execute(array(':tran_id' => $tran_id, ':user_name_buyer ' => $_SESSION['user_name']));
$user = $sth->fetch();
You're binding a :tran_id parameter during your call to execute, but you're not using that parameter in your query.
Change your execute line to this
$sth->execute(array(':user_name_buyer ' => $_SESSION['user_name']));
Remove :tran_id from your parameter list or add a condition for that parameter. I hope this help.
Your select statement does not have a where clause for tran_id, either remove the tran_id from your execute call
$sth->execute(array(':user_name_buyer ' => $_SESSION['user_name']));
or add a extra where clause to your sql statement
$sql = "SELECT tran_id, seller_user_name, user_name_buyer
FROM trade_transaction, feedback
WHERE feedback.feedback_username = trade.user_name_of_buyer
AND tran_id = :tran_id
AND user_name_of_buyer = :user_name_buyer ";
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
I've done a search and couldn't find anything that could specifically help me.
I was hoping you could help.
I'd like to execute a MySQL query which searches a table for entries which meet two criteria (type = green AND on = yes)
I am presented with: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /link/to/my/file.php on line 36
Here is an extract from the code (line 36):
`$green = "SELECT * FROM homepage_vars WHERE type = 'green' AND on = 'yes'";
$green = mysql_query($green);
$green = mysql_fetch_array($green);`
ON is a MySQL reserved keyword. If you use it as a column or table identifier, you need to enclose it in backquotes:
SELECT * FROM homepage_vars WHERE type = 'green' AND `on` = 'yes'
You'll then have another problem once the query syntax is corrected. You have overwritten the variable $green several times. Originally, it held your query SQL, but was then used for the query result resource. That's fine, but then you will overwrite it with the row fetched by mysql_fetch_array() and its contents will be an array or FALSE. Subsequent attempts to fetch rows will fail since $green is no longer a result resource.
Always test for query success or failure before attempting to fetch rows. Call mysql_error() to see the error reported by the MySQL server, which would have pointed to invalid syntax near 'on or something similar.
$green = "SELECT * FROM homepage_vars WHERE type = 'green' AND on = 'yes'";
$query = mysql_query($green);
if ($query) {
// Don't overwrite your query resource!
// Use a new variable!
$row = mysql_fetch_array($query);
}
else {
// Failure!
echo mysql_error();
}