I hopefully seem to be getting somewhere from my last post about creating a database script. But now I seem to be getting an error with the following:
Notice: Undefined offset: 10 in /var/www/mysite/include/config.php on line 126
So its this line 126 that the output will not produce:
$price = $col[10];
I ran the query in phpmyadmin to make sure it was working:
SQL result
Host: localhost
Database: mydb
Generation Time: May 14, 2013 at 04:56 PM
Generated by: phpMyAdmin 3.5.8.1deb1 / MySQL 5.5.31-0ubuntu0.13.04.1
SQL query: SELECT * FROM packages WHERE service = 'books' LIMIT 1;
Rows: 1
service plan title author descr type language paperback currency price
books weekly a b c d e f g h
Here is the code:
$book_query = ("SELECT * FROM packages WHERE service = ? LIMIT 1");
if(!$book_stmt = $pdo->prepare($host_query)){
// prepare failed
echo "<pre>Prepare failed:\n";
print_r($pdo->errorInfo());
echo "</pre>";
} else {
if(!$book_stmt->execute(array('books'))){
// execute failed
echo "<pre>Execute failed:\n";
print_r($book_stmt->errorInfo());
echo "</pre>";
} else {
// query ran without any errors, you can test if it returned any rows and use them here
}
}
// Database
if ($book_stmt->rowCount() > 0) {
while ($col = $book_stmt->fetch())
{
$title = $col[3];
$author = $col[4];
$descr = $col[5];
$type = $col[6];
$language = $col[7];
$paperback = $col[8];
$currency = $col[9];
$price = $col[10];
}
} else {
$title = 'no data';
$author = 'no data';
$descr = 'no data';
$type = 'no data';
$language = 'no data';
$paperback = 'no data';
$currency = 'no data';
$price = 'no data';
}
What can I do to correct this?