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.
IMHO your
INSERTstatement should look like this:And you definitely need to consider sanitizing input and using prepared statements.
Update:
You can populate your
selectwith options from Table 2 (and assuming that you usemysqli) you can do something like this:For sake of brevity and simplicity there are no checks.