PDOException error when running SQL Query in PDO [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am trying to run this SQL Query using PHP PDO:
$stmt = $pdo_conn->prepare("select * from billing_pdf_archive where invoice_number = :invoice_number and sequence = :sequence ");
$stmt->execute(array(
':invoicenumber' => $_GET["inv"],
':sequence' => $_GET["seq"]
)
);
$result = $stmt->fetch();
Note: $_GET["inv"] and $_GET["seq"] show data when echoed
but i am getting this error
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in /home/integra/public_html/lifeline/billing/resendpdfinvoice.php:94 Stack trace: #0 /home/integra/public_html/lifeline/billing/resendpdfinvoice.php(94): PDOStatement->execute(Array) #1 {main} thrown in /home/integra/public_html/lifeline/billing/resendpdfinvoice.php on line 94
i cannot work out what is wrong with it

where invoice_number = :invoice_number
^---- underscore here
$stmt->execute(array(':invoicenumber' => $_GET["inv"],
^---no underscore here

See here
invoicenumber!=invoice_number

It appears that your query contains :invoice_number when your execution statement asks for :invoicenumber. Try setting them to the same value (:invoice_number for example)
$stmt = $pdo_conn->prepare("select * from billing_pdf_archive"
. " where invoice_number = :invoice_number and sequence = :sequence ");
$stmt->execute(array(
':invoice_number' => $_GET["inv"],
':sequence' => $_GET["seq"]
));
$result = $stmt->fetch();

Related

PDO - Error with number of bound variables [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have this error when I run the code:
Error:
Invalid parameter number: number of bound variables does not match number of tokens - Line: 106
Code:
$data_cadastro = date("Y-m-d G:i:s");
$query = "INSERT INTO FRETES (VENDA_CLIENTE_ID_CLIENTE, VENDA_ID_VENDA, DT_COLETA, DT_ENTREGA, LINK, TRANSPORTADORA, POSICAO, VALIDA, DT_CADASTRO)
VALUES (:id_cliente, :id_venda, ':dt_coleta', ':dt_entrega', ':link', ':transportadora', ':posicao', :validacao, ':dt_cadastro')";
$banco = $this->pdo->prepare($query);
try {
$banco->execute(
array(
':id_cliente' => $this->id_cliente,
':id_venda' => $this->id_venda,
':dt_coleta' => $dados['DTcoleta'],
':dt_entrega' => $dados['DTentrega'],
':link' => $dados['linkFrete'],
':transportadora' => $dados['transportadora'],
':posicao' => $dados['posicaoFrete'],
':validacao' => $dados['validacao'],
':dt_cadastro' => $data_cadastro
)
);
} catch (PDOException $exception) {
die("Execução da Query com erro (inserir novo frete): " . $exception->getMessage() . ' - Linha: ' . $exception->getLine());
}
Where i wrong?
Remove the quotes around the placeholders
$query = "INSERT INTO FRETES
(VENDA_CLIENTE_ID_CLIENTE, VENDA_ID_VENDA, DT_COLETA,
DT_ENTREGA, LINK, TRANSPORTADORA, POSICAO, VALIDA, DT_CADASTRO)
VALUES (:id_cliente, :id_venda, :dt_coleta, :dt_entrega, :link,
:transportadora, :posicao, :validacao, :dt_cadastro)";

How to convert PDO to MYSQLi [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm following this tutorial, but my problem is that everything is written for PDO, but the my website is MySQLi.
I've been trying to just search for conversions on www.php.net (for example; $statement = $db->prepare($query); = $statement = $db->mysqli_prepare($query) (source))
This is my code that doesn't work:
<?php
$query = "
SELECT shape FROM inventory
";
$statement = $db->mysqli_prepare($query)
$statement->mysqli_execute();
$result = $statement->mysqli_fetch()
foreach($result as $row) {
?>
<!-- HTML code here -->
<?php } ?>
It's supposed to query the shape column from the database but I keep getting this error Fatal error:
Uncaught Error: Call to a member function stmt_init() on null in /homepages/7/d410968336/htdocs/Inventory/vendors/php/Filters/Filters.php:68 Stack trace: #0 {main} thrown in /homepages/7/d410968336/htdocs/Inventory/vendors/php/Filters/Filters.php on line 68
(in this case line 7 $statement = $db->mysqli_prepare($query))
Well, first in a simple select query you really don't need the prepared statement. but if you wanna do I think this would help you.
$query = "SELECT shape FROM inventory";
$statement = mysqli_prepare($db, $query);
mysqli_stmt_execute($statement);
while(mysqli_stmt_fetch($statement)){
....
}

PDOException: Query was empty [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have a PDO PHP file making use of just one $_POST value stored on the $data array, and if an statement is true, a second value is added to that array to make a new query with two values:
<?php
session_start();
include("../conexionbbdd.php");
if($_SESSION['estado'] == 'activo' && $_SESSION['rol'] == '1'){
$data = array(
'us_id' => $_POST['us_id'],
);
$selectUsers= "SELECT * FROM ws_users WHERE us_id= :us_id";
$statementSelectUsers = $pdo->prepare($selectUsers);
$statementSelectUsers->execute($data);
$result = $statementSelectUsers->fetch(PDO::FETCH_ASSOC);
$us_fk_ui_id = $result['us_fk_ui_id'];
if($us_fk_ui_id==='1'){
$data['us_credits']=$_POST['us_credits'];
$updateUser = mysqli_query($con,"UPDATE ws_users SET us_credits = :us_credits, us_access = '1' WHERE us_id = :us_id");
$statementUpdateUser = $pdo->prepare($updateUser);
$statementUpdateUser->execute($data);
}
Everything goes fine untill the $statementUpdateUser->execute($data); line (34), where I get the usual error
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1065
Query was empty in C:\wamp\www**********\actions\ad_updateUserInfo.php on
line 34
As far as I've seen, this should be due to the unexistance of one of the placeholders on the array, but if I print the array values after the $data['us_credits']=$_POST['us_credits']; it seems to be correct, having the 2 expected values needed for my query:
Array (
[0] => 2
[1] => 1.5 )
How could I check where the mistake is? There's no possibility of echoing the query as it is an object unable to transform on string.
$updateUser = mysqli_query($con,"UPDATE ws_users SET us_credits = :us_credits, us_access = '1' WHERE us_id = :us_id");
^^^ WTF??
You have to pay more attention to the code you write. Stack Overflow is NOT the service for finding typos for you.

PDO Invalid parameter number: parameter was not defined [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Im having a strange issue with a select with PDO, so I came here to ask for your help.
I have this code below and Im getting this error:
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number:
parameter was not defined in `$verifyUser->execute();`
Somebody there have an ideia why this can be happening?
My Php Code:
if(!$_SESSION['result'])
{
header('Location: index.php');
}
else
{
$userId = $_SESSION['result']['id'];
$verifyUser = $pdo->prepare("SELECT * FROM aadmins where id = :userId");
$verifyUser->bindValue(":id", $userId);
$verifyUser->execute();
$num_rows = $verifyUser->rowCount();
$result = $verifyUser->fetch(PDO::FETCH_ASSOC);
}
You are using :userId in SQL query, while in bindValue you are using :id.
$verifyUser = $pdo->prepare("SELECT * FROM aadmins where id = :userId");
$verifyUser->bindValue(":id", $userId);
But it should be the same in query and bindvalue.
$verifyUser = $pdo->prepare("SELECT * FROM aadmins where id = :id");
$verifyUser->bindValue(":id", $userId);

PDO Prepared statement Uncaught exception error message [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
i am trying to run this PDO Prepared statement
$stmt = $pdo_conn->prepare(
"INSERT into email_attachments (email_seq, attachment)
values (:email_seq, :attachment) ");
$stmt->execute(array(
':email_seq' => $admin_email_sequence,
':attachment' => $_SERVER["DOCUMENT_ROOT"].'/'.$settings["ticket_files_folder"].'/'.$ticketnumber.'-'.$currentDate.'-'.$at[filename], $at[attachment]
));
but I'm getting this error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in /home/integra/public_html/autocheck/support_emails.php:662 Stack trace: #0 /home/integra/public_html/autocheck/support_emails.php(662): PDOStatement->execute(Array) #1 {main} thrown in /home/integra/public_html/autocheck/support_emails.php on line 662
At the very end of the :attachment entry you have a comma instead of what I assume should be a period.
.$at[filename], $at[attachment]
^-- here
This causes the Exception because you have 2 labels in your query, and 3 elements in your array.
You have an extra ) inside your execute array, also you have an extra array element ($at[attachment])
Try this code
$stmt = $pdo_conn->prepare("INSERT into email_attachments (email_seq, attachment) values (:email_seq, :attachment) ");
$stmt->execute(array(
':email_seq' => $admin_email_sequence,
':attachment' => $_SERVER["DOCUMENT_ROOT"] . '/' . $settings["ticket_files_folder"] . '/' . $ticketnumber . '-' . $currentDate . '-' . $at[filename]
));

Categories