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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:47:12+00:00 2026-06-10T12:47:12+00:00

I am using the primary key of the room_extras table to create a unique

  • 0

I am using the primary key of the room_extras table to create a unique name for my extra text field.

Here’s the example:

<tr>
    <td><?php echo $extrasInfo['description'] ?></td>
    <td>
        <input type="text" name="extra[<?php echo $extrasInfo['re_id'] ?>]" id="qty" value="0" style="text-align: right" size="5" onKeyPress="return isNumberKey(event)" />
    </td>
    <td align="right"><?php echo number_format($extrasInfo['price'],2) ?></td>
</tr>

As you can see the name is generated using this code extra[<?php echo $extrasInfo['re_id'] ?>].

The result of this in html is:

<tr>
    <td colspan="3"><h3>Economy Room</h3></td>
</tr>
<tr>
    <td>Extra Person</td>
    <td><input type="text" name="extra[19]" id="qty" value="1" style="text-align: right" size="5" onKeyPress="return isNumberKey(event)"></td>
    <td align="right">560.00</td>
</tr>
<tr>
    <td>Breakfast for Extra Person</td>
    <td><input type="text" name="extra[20]" id="qty" value="1" style="text-align: right" size="5" onKeyPress="return isNumberKey(event)"></td>
    <td align="right">150.00</td>
</tr>
<tr>
    <td colspan="3"><h3>Deluxe</h3></td>
</tr>
<tr>
    <td>Extra Person</td>
    <td><input type="text" name="extra[1]" id="qty" value="0" style="text-align: right" size="5" onKeyPress="return isNumberKey(event)"></td>
    <td align="right">730.00</td>
</tr>
<tr>
    <td>Breakfast for Extra Person</td>
    <td><input type="text" name="extra[2]" id="qty" value="0" style="text-align: right" size="5" onKeyPress="return isNumberKey(event)"></td>
    <td align="right">269.00</td>
</tr>

Depending on the value of re_id field (i.e. $extrasInfo['re_id']) the array return a different key like:

extra[19]
extra[20]
extra[1]
extra[2]

So my question is how do I get the value after “extra”? That is, the numbers 19, 20, 1, and 2.

Here’s what I have started:

$size = count($_POST['extra']);

$i = 0;
while ($i < $size) {
    $qty = $_POST['extra'][$i];
    $re_id = ????; //what should be the code here?

    $query = "$sql_extras="INSERT INTO `lf_bookings_extras`(`re_id`, `booking_number`, `price`, `qty`, `amount`) VALUES ('$re_id','$booking_number','$price','$qty','$amount')";";

    mysql_query($query) or die ("Error in query: $query");

    ++$i;
}
  • 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-10T12:47:13+00:00Added an answer on June 10, 2026 at 12:47 pm

    You should not name your extra array from form input, that way you can loop in that array.

    $re_id = $_POST['extra'][$i];
    

    and HTML

    <input type="text" name="extra[]" id="qty" value="1" style="text-align: right" size="5" onKeyPress="return isNumberKey(event)">
    

    or if you really want to do that

    foreach($_POST['extra'] as $key => $val){
        $qty = $val;
        $re_id = $key;
        // $key will be the id passed from input
        // mysql insert
    }
    

    PS: please, don’t use mysql_* functions for new code. They are no longer maintained and the community has begun the deprecation process. See the red box? Instead you should learn about prepared statements and use either PDO or MySQLi. If you can’t decide, this article will help to choose. If you care to learn, here is a good PDO tutorial.

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

Sidebar

Related Questions

I'm using SQL Server 2005 with a table with a primary key field with
Firstly, by using Primary key am I applying the UNIQUE constraint properly? <?php //
I can create a Primary Key using Navicat in the Design Table section of
Am using the following notation to add a primary key to a table: ALTER
I'm trying to populate a field called 'identification' using the primary key 'id'. However,
I need to insert records into a table that has no primary key using
I'd like to save my files using the primary key of the entry. Here
I have a table called Picture in my database. I'm using the primary key
Using Postgres, I'm trying to use AUTO_INCREMENT to number my primary key automatically in
The team I'm working with decided to create a table with a varchar primary

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.