Q:

My query wont execute

I've been working on a script that includes an installer and now I'm stuck in a part where I can't have my query executed. I'm using PDO.
So, my problem is that the two queries inside the second try block are not being executed.
This is my code:
<?php
$root_path = '../';
require("{$root_path}includes/functions_captcha.php");

$sub    = (isset($_GET['sub'])) ? $_GET['sub'] : '';
$step   = (isset($_POST['step'])) ? (int) $_POST['step'] : 0;
$submit = (isset($_POST['submit'])) ? true : false;

$driver_options = '';
$db_errors = array();

$drivers = PDO::getAvailableDrivers();
foreach ($drivers as $driver)
{
    $driver_options .= '<option value="' . $driver . '">' . $driver . '</option>';
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Q&amp;A CAPTCHA &bull; Installation</title>
    <link type="text/css" rel="stylesheet" href="../admin/style/stylesheet.css" />
</head>
<body>
    <div id="main">
        <a href="index.php"><h1>Q&amp;A CAPTCHA Installation</h1></a>

        <div class="content">
            <?php if (!$sub || ($sub == 'database' && !$step) && !$submit): ?>
            <form method="post" action="?sub=database">
            <table width="100%">
                    <tr class="table_top">
                        <th align="center" colspan="2">Database settings</th>
                    </tr>

                <tr class="row1">
                    <td><strong>Database type:</strong></td>
                    <td><select name="driver"><?php echo $driver_options; ?></select></td>
                </tr>
                <tr class="row2">
                    <td><strong>Database server hostname:</strong></td>
                    <td><input type="text" name="hostname" placeholder="localhost" required value="" /></td>
                </tr>
                <tr class="row1">
                    <td><strong>Database name:</strong></td>
                    <td><input type="text" name="name" required value="" /></td>
                </tr>
                <tr class="row2">
                    <td><strong>Database username:</strong></td>
                    <td><input type="text" name="username" required value="" /></td>
                </tr>
                <tr class="row1">
                    <td><strong>Database password:</strong></td>
                    <td><input type="password" name="password" value="" /></td>
                </tr>
                <tr>
                    <td align="center" colspan="2">
                        <input type="submit" name="submit" value="Proceed to next step &raquo;" />
                        <input type="hidden" name="step" value="2" />
                    </td>
                </tr>
            </table>
            </form>
            <?php endif; ?>
            <?php if ($sub == 'database' && $step == 2 && $submit): ?>
                <?php 
                    try {
                        $db = new PDO("{$_POST['driver']}:host={$_POST['hostname']};dbname={$_POST['name']}", $_POST['username'], $_POST['password']);

                        try {
                            $db->beginTransaction();
                            $time = time();

                            $sql = "CREATE TABLE captcha_config (
                                id mediumint(8) UNSIGNED NOT NULL auto_increment,
                                question varchar(255) DEFAULT '' NOT NULL,
                                date int(11) UNSIGNED DEFAULT '0' NOT NULL
                                answers TEXT DEFAULT '' NOT NULL);";
                            $db->query($sql);

                            $sql = "INSERT INTO captcha_config 
                                (question, date, answers) VALUES (
                                'What color can the sky have?', {$time}, 'Blue~~Grey~~Orange');";
                            $db->query($sql);

                            $db->commit();
                        }
                        catch (PDOException $e)
                        {
                            $db->rollBack();
                            $db_errors[] = (strpos($e->getMessage(), ']') !== false) ? substr(strrchr($e->getMessage(), ']'), 1) : $e->getMessage();
                        }
                    }
                    catch (PDOException $e)
                    {
                        $db_errors[] = (strpos($e->getMessage(), ']') !== false) ? substr(strrchr($e->getMessage(), ']'), 1) : $e->getMessage();
                    }

                    $db_errors = implode('<br />', $db_errors);
                ?>
            <form method="post" action="?sub=config">
            <table width="100%">
                <tr class="table_top">
                    <th align="center" colspan="2">Database connection</th>
                </tr>
                <tr class="row1">
                    <td align="center"><?php echo (empty($db_errors)) ? '<strong style="color: green;">Connection was successful</strong>' : "<strong style='color: red;'>{$db_errors}</strong>"; ?></td>
                </tr>
                <tr>
                    <td align="center">
                        <?php if (empty($db_errors)): ?> 
                            <input type="submit" name="submit" value="Proceed to next step &raquo;" />
                        <?php else: ?> 
                            <a href="index.php" class="button">&laquo; Back to previous step</a>
                        <?php endif; ?>
                        <input type="hidden" name="step" value="3" />
                    </td>
                </tr>
            </table>
            </form>
            <?php endif; ?>
        </div>
    </div>
</body>
</html>

A:

you were missing a comma in your create table stmt plus the primary key line
                    try {

                        $db->beginTransaction();
                        $time = time();
                        $sql = "CREATE TABLE captcha_config (
                            id mediumint(8) UNSIGNED NOT NULL auto_increment,
                            question varchar(255) DEFAULT '' NOT NULL,
                            date int(11) UNSIGNED DEFAULT '0' NOT NULL,
                            answers TEXT DEFAULT '' NOT NULL,
            PRIMARY KEY (id));";
                        $db->query($sql);

                        $sql = "INSERT INTO captcha_config 
                            (question, date, answers) VALUES (
                            'What color can the sky have?', {$time}, 'Blue~~Grey~~Orange');";
                        $db->query($sql);

                        $db->commit();
                    }

show tables:
+----------------------+
| Tables_in_jonah_junk |
+----------------------+
| _adminfiles          |
| _adminlang           |
| _adminlog            |
| _adminprivs          |
| _adminroles          |
| _adminusers          |
| captcha_config       |
| sometable            |
+----------------------+
8 rows in set (0.00 sec)

mysql> select * from captcha_config;
+----+------------------------------+------------+--------------------+
| id | question                     | date       | answers            |
+----+------------------------------+------------+--------------------+
|  1 | What color can the sky have? | 1353940684 | Blue~~Grey~~Orange |
+----+------------------------------+------------+--------------------+

