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

The Archive Base Latest Questions

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

I have 2 tables Table 1 and Table 2 . What I expect is

  • 0

I have 2 tables Table 1 and Table 2 .

What I expect is the below format.
Required format

Table 1    
   ID   Title   S_ID    
   1    Option1   2    
   2    Option2   2    
   3    Option3   1  

Table 2       
   S_ID  SNAME    
   1     Name1    
   2     Name2    
   3     Name3    

But I am getting a null value for S_ID of Table1.

Table 1    
   ID   Title   S_ID    
   1    Option1   NULL    
   2    Option2   NULL    
   3    Option3   NULL

Table 2    
   S_ID  SNAME    
   1     Name1    
   2     Name2    
   3     Name3    

Here is my code:

HTML :

<select name=sid>
<option value="select"></option>
<option value="N1">Name1</option>
<option value="N2">Name2</option>
<option value="N3">Name3</option>
</select>    

Insert.php

$title=$_POST['title'];
$sid=$_POST['S_ID'];    
$insertquery="INSERT INTO review (title) VALUES('$title')";    

What I need is when I select any name from drop down, the id of that from Table 2 should get stored in Table 1 as shown in the above required format, and retrieve the titles that comes under respective names on click of particular name.

Do help by writing required code. Thank You.

  • 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-17T08:25:15+00:00Added an answer on June 17, 2026 at 8:25 am

    IMHO your INSERT statement should look like this:

    $insertquery = "INSERT INTO review (title, S_ID) VALUES('$title', '$sid')";
    

    And you definitely need to consider sanitizing input and using prepared statements.

    Update:

    You can populate your select with options from Table 2 (and assuming that you use mysqli) you can do something like this:

    <?php
    
    $db = new mysqli("host", "user", "password", "db");
    
    $qry = "SELECT * FROM Table2";
    $result = $db->query($qry);
    echo "<select name=\"S_ID\">";
    echo "<option value=\"select\" selected=\"selected\">Select a name</option>";
    while ($row = $result->fetch_array(MYSQL_ASSOC)) {
        echo "<option value=\"" . $row['S_ID'] . "\">" . $row['SNAME'] . "</option>";
    }
    echo '</select>';
    $result->close();
    $db->close();
    
    ?>
    

    For sake of brevity and simplicity there are no checks.

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

Sidebar

Related Questions

I have two tables: Table_A name1 create_date Table_B name2 keep_time name1 is something like
I have two Tables: Table 1: Questions : QuestionId NUMERIC Title TEXT Test Data
When I have the below two tables, would the StatusTypes table be considered as
I have two tables: table a ida valuea 1 a 2 b 3 c
I have 2 tables Table A NameID FirstName MiddleName LastName Addr1 Addr2 Phn1 Phn2
I have two tables: Table GL TRANS_NBR BASE_AMOUNT CTRL GRP 120211282 -7200 77 120211282
I have two tables Table public.tags_to_entities Column | Type | Modifiers --------+---------+----------- tid |
Please have a look at the SQL below: create table ChecksumTest (id int not
I use SQL Server 2005 and have the below question: On a table A
I have CSS definitions for various elements around Table as shown below (Details omitted,

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.