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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:17:25+00:00 2026-05-23T02:17:25+00:00

I have several select statements that look like this. I need to pass the

  • 0

I have several select statements that look like this. I need to pass the php variable into my database.

 <select name="gamestart" >
 <?php for($gamestart=1; $gamestart<=24; $gamestart++)
 echo "<option value='$gamestart'>$gamestart:00</option>"; 
 ?>
 </select>

Here is my insert statement into my database with other similar variables where I have the same issue.

     <?php 
   $mysql_query = "INSERT INTO soccer_games (gamestart, gameend)
        VALUES ('$gamestart', '$gameend')";

    $this->db->query($mysql_query);
   ?>

As of now, values are being put into the database but the value that is INSERT’ed into the database is the number 25 (not even an option in my loop as you can see) regardless of what value I select in the form.

===============

EDIT 1:
The problem would probably be that I haven’t used a form (Me in my infinite wisdom didn’t realize I needed a form for this).

I am assuming I will need something of this nature…

public function insertstatements(){
<?php 
   $mysql_query = "INSERT INTO soccer_games (gamestart, gameend)
        VALUES ('$gamestart', '$gameend')";

    $this->db->query($mysql_query);
   ?>
}


<form method="post" action="<?php insertstatements(); ?>">


 <select name="gamestart" >
 <?php for($gamestart=1; $gamestart<=24; $gamestart++)
 echo "<option value='$gamestart'>$gamestart:00</option>"; 
 ?>
 </select>
</form>
  • 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-23T02:17:26+00:00Added an answer on May 23, 2026 at 2:17 am

    You can access the gamestart sent from the form using either $_POST['gamestart'] or $_GET['gamestart'] depending on the method set in your form (if there is no method attribute, it will be GET).

    Your $gamestart is set to 25 before I guess the for loop is before your database insertion logic, so its value will be set to 25.

    Be sure to use mysql_real_escape_string on your variable before putting it into the query, otherwise you might suffer some SQL injection attacks, quite easily. Never trust user input!

    So a correct example would be (I don’t know where you’re getting $gameend from, but if it’s also from the form, do the same with it):

    $gamestart=mysql_real_escape_string($_POST['gamestart']);
    $mysql_query = "INSERT INTO soccer_games (gamestart, gameend)
            VALUES ('$gamestart', '$gameend')";
    

    EDIT: You can access your GET and POST variables simply as $gamestart if you have register_globals enabled. But you should turn it off, and not write any code that depends on it. For the whys, search for it on Google.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MySQL. I have several lookups like this: SELECT * from users
I have a PHP script with one select query and several prepared update statements.
I have a query that makes several calls within a SELECT statement to a
I have a DataTable which I select from database (Well, these data cross several
I have several statements which access very large Postgresql tables i.e. with: SELECT a.id
I have several laptops in the field that need to daily get information from
I have several DAO objects that are used to retrieve information from a database
I have several instances where that a section of legacy sql statements is based
I currently have several if statements that populate a specific table after the button
I have a database table with several columns in it. I want to select

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.