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 ";
Related
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 3 years ago.
I made a table that holds post and likes and I'm trying to output the of everything in the table but I get the
error: mysqli_num_rows() expects parameter 1 to be mysqli_result,
boolean given on line 18.
$sql3 = "SELECT * FROM post;";
$result = mysqli_query($conn,$sql3);
$datas = array();
if (mysqli_num_rows($result)> 0){
while($row = mysqli_fetch_assoc($result)){
$datas[] = $row;
}
}
foreach ($datas as $data){
echo $data;
}
I expect the all the information to be outputted, but the actual output is
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean
given on line 18.
This means that your query is returning false instead of a mysqli_result object. The problem appears to be from the semicolon at the end of your statement. I believe that mysqli will see that as a multistatement. From https://www.php.net/manual/en/mysqli.quickstart.multiple-statement.php:
Multiple statements or multi queries must be executed with mysqli_multi_query(). The individual statements of the statement string are separated by semicolon. Then, all result sets returned by the executed statements must be fetched.
mysqli has a method to get the last error it encountered:
https://www.php.net/manual/en/mysqli.error.php
Example:
if(!$result){
printf("Error message: %s\n", mysqli_error($conn));
}
This question already has an answer here:
Can I use a PDO prepared statement to bind an identifier (a table or field name) or a syntax keyword?
(1 answer)
Closed 5 years ago.
I'm failing to see the problem why I'm getting a pdo error, I'm not missing a simple : or a parameter (since there are only 2)
public function does_stringid_excist($strTable, $strColumn, $strValue)
{
$sql = "SELECT count(1) AS count FROM tblemployer WHERE :strColumn = :strValue";
$this->objDatabase->query($sql); //Makes a prepare with the given sql
// $this->objDatabase->bind_column(':strTable', $strTable);
$this->objDatabase->bind_column(':strColumn', $strColumn); // Uses the `bindColumn()` from PDO
$this->objDatabase->bind_value(':strValue', $strValue); // Uses the `bindValue()` from PDO
$result = $this->objDatabase->single();
return $result['count'];
}
SELECT count(1) AS count FROM `tblemployer` WHERE `employerID` = :strValue" works just fine so the error isn't with the value.
A column is not the same as a table. Youre using bindColumn to bind a table, which does not work.
See: http://php.net/manual/en/pdostatement.bindcolumn.php
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 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();
}
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 am getting this error while trying to run a function. I am sending a value $id to this function and trying to return the associated array. But I get a warning supplied argument is not a valid MySQL-Link resource.
But if i run the same code by eliminating the function part and give a static value to $id it returns the result correctly. This is the function
<?php
mysql_select_db($database_spyware, $spyware);
function get_product($id)
{
$query = sprintf("select product.descr as product_descr, product_id as Product_id,
category.descr as category from sp_url
inner join product
on product.id = sp_url.product_id
inner join category
on product.category_id = category.id
where sp_url.id = $id");
$query_result = mysql_query($query, $spyware) or die(mysql_error());
$row_rs_query = mysql_fetch_assoc($query_result);
$totalRows_rs = mysql_num_rows($query_result);
return($row_rs_query);
}
?>
That happens because your second parameter spyware in function "mysql_query" is declared outside the function and is unreadable on your function scope.
try
global $spyware;
at the beginning of the function.
or leave the second parameter empty.