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 3444446
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:54:59+00:00 2026-05-18T08:54:59+00:00

I have a table in MySQL to contain user created anti-bot questions. When installing

  • 0

I have a table in MySQL to contain user created anti-bot questions. When installing the tables however, I want to insert some default anti-bot questions beforehand. I came up with the following code but I’m not sure exactly how to put it into the correct syntax. Basically, I created two arrays (one for questions and another for answers, in respective and matching order.) and want to cycle through each pair of question and answer using the foreach() or perhaps the while() function.

Here’s my code:

$questions = array(
 "question1"   =>   "What is 2+6?",
 "question2"   =>   "What color is the sky?",
 "question3"   =>   "What number is betwee 6 and 8?",
 "question4"   =>   "How many letters are there in the English alphabet?",
 "question5"   =>   "How many hours are there in a day?",
 "question6"   =>   "Are you a human or a bot?"
);
$answers = array(
 "answer1"   =>   "8",
 "answer2"   =>   "blue",
 "answer3"   =>   "7",
 "answer4"   =>   "26",
 "answer5"   =>   "24",
 "answer6"   =>   "human"
);
$x = 0;
foreach ($question[$x]) {
$sql = "INSERT INTO
 administrator_instructions
  (question, question_naswer)
 VALUES
  ('" . $question[$x] . "','" . $answer[$x] . "')";
$x++;
}
  • 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-05-18T08:55:00+00:00Added an answer on May 18, 2026 at 8:55 am

    Something along the line of:

    $q_a = array(
        'what is 2 + 6' => '8',
        'what color is the sky?' => 'blue',
        // etc ...
    }
    $i = 0;
    $cnt = count(array_keys($q_a));
    $sql = 'insert into administrator_instructions (question, question_answer) values ';
    foreach ($q_a as $q => $a) {
        $sql .= sprintf("('%s', '%s')", mysql_real_escape_string($q), mysql_real_escape_string($a));
        $i++;
        if($i < $cnt) $sql .= ", ";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which already contains an index in MySQL. I added some
What I have is two tables inside of a mysql database. One table contains
I have a directory table in a MySQL database that contains user ID's, user
I have a MySQL table for persistence of some Java objects and use Hibernate
Into I have two tables profile and name , the profile table contains some
I have a misunderstanding regarding some dynamic row inserts in a MySQL table. All
I have two tables in my MySQL database, users and tweets, as follows: TABLE
I have table in mysql which contain fields id, username, password and salt: Example:
I have table which contains double values stored in mysql database ...I need to
I have a mysql table (table-A) that contains a list of unique product ids.

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.