Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8889531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:17:06+00:00 2026-06-14T22:17:06+00:00

I’ve been working on a script that includes an installer and now I’m stuck

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:17:08+00:00Added an answer on June 14, 2026 at 10:17 pm

    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 |
    +----+------------------------------+------------+--------------------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a small JavaScript validation script that validates inputs based on Regex. I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.