Reputation: 1358
I created a PDO object and an INSERT INTO
query using array parameters, like so:
$pdo = new PDO('mysql:host=localhost;dbname=cluster', 'root', '');
if(!$pdo) {
throw new PDOException("Failed connection!");
}
$qry = $pdo->prepare("INSERT INTO visitors_table(visitor_ip, visitor_browser, visitor_hour, visitor_minute, visitor_day, visitor_month, visitor_year, visitor_refferer, visitor_page) "
. "VALUES (:visitor_ip, :visitor_browser, :visitor_hour, :visitor_minute, :visitor_day, :visitor_month, :visitor:year, :visitor_refferer, :visitor_page)");
$arg = array(
'visitor_ip' => $guest_ip,
'visitor_browser' => $guest_browser,
'visitor_hour' => date('H'),
'visitor_minute' => date('i'),
'visitor_day' => date('D'),
'visitor_month' => date('M'),
'visitor_year' => date('Y'),
'visitor_refferer' => '',
'visitor_page' => ''
);
But if I do
<?php if($qry->execute($arg) > 0): ?>
Successful input!
<?php else: ?>
Unsuccessful input!
<?php endif; ?>
I get the following response:
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\xampp\htdocs\Cluster\index.php on line 47 Unsuccessful input!
I tried to find the 'missing parameter', but everything just seams in order to me... Did I go blind and miss something obvious or is there something else to it?
Side question: For PHP programmers, is this the kind of indenting and naming you'd find readable and easy to follow?
Upvotes: 0
Views: 63
Reputation: 6696
You have a typo:
$qry = $pdo->prepare("INSERT INTO visitors_table(visitor_ip, visitor_browser,
visitor_hour, visitor_minute, visitor_day, visitor_month, visitor_year,
visitor_refferer, visitor_page) "
. "VALUES (:visitor_ip, :visitor_browser, :visitor_hour, :visitor_minute, :visitor_day,
:visitor_month, :visitor_year, :visitor_refferer, :visitor_page)");
^here
Upvotes: 1