Hi friends,
I had posted the problem a couple of months ago, but didn't get my answer. Finally; I found a code to
retrieve data from database and populate it in two related listbpxes (drop downs). Now, I need to
insert the selected data into another table in my database again. How can I do that? Is there any idea?
I will paste the code below.
I would be grateful to have your guides.
Thanks in advance,
Mojgan
I have a table user_occupations1 with "id, category and parent" as fields.
Table structure for table res_occupations1
CREATE TABLE res_occupations1 (
id double NOT NULL default '0',
Category varchar(255) default NULL,
Parent double default NULL,
PRIMARY KEY (id),
KEY id (id)
) TYPE=MyISAM;
#
Dumping data for table res_occupations1
#
INSERT INTO res_occupations1 VALUES ('2', 'Civil Engineering', '0');
INSERT INTO res_occupations1 VALUES ('3', 'Mechanical Engineering', '0');
INSERT INTO res_occupations1 VALUES ('4', 'Electrical and Electronics Engineering', '0');
INSERT INTO res_occupations1 VALUES ('5', 'Chemical Engineering', '0');
INSERT INTO res_occupations1 VALUES ('6', 'Industrial and Manufacturing Engineering', '0');
INSERT INTO res_occupations1 VALUES ('7', 'Metallurgical and Materials Engineering', '0');
INSERT INTO res_occupations1 VALUES ('8', 'Mining Engineering', '0');
INSERT INTO res_occupations1 VALUES ('9', 'Geological Engineering', '0');
INSERT INTO res_occupations1 VALUES ('10', 'Petroleum Engineering', '0');
INSERT INTO res_occupations1 VALUES ('11', 'Aerospace Engineering', '0');
INSERT INTO res_occupations1 VALUES ('12', 'Computer Engineering (Except Software Engineering)', '0');
INSERT INTO res_occupations1 VALUES ('13', 'Other Professional Engineering, n.e.c.', '0');
INSERT INTO res_occupations1 VALUES ('21', 'Software Engineering', '0');
INSERT INTO res_occupations1 VALUES ('31', 'airport', '2');
INSERT INTO res_occupations1 VALUES ('32', 'appraisal', '2');
INSERT INTO res_occupations1 VALUES ('33', 'architectural', '2');
INSERT INTO res_occupations1 VALUES ('124', 'cryogenics', '3');
INSERT INTO res_occupations1 VALUES ('125', 'design - mechanical', '3');
INSERT INTO res_occupations1 VALUES ('126', 'design, oil well equipment', '3');
INSERT INTO res_occupations1 VALUES ('128', 'diesel - design and research', '3');
INSERT INTO res_occupations1 VALUES ('173', 'analogue amplifier design', '4');
INSERT INTO res_occupations1 VALUES ('174', 'antenna', '4');
INSERT INTO res_occupations1 VALUES ('175', 'audio - electricity and electronics', '4');
INSERT INTO res_occupations1 VALUES ('176', 'avionics', '4');
INSERT INTO res_occupations1 VALUES ('249', 'adhesives', '5');
INSERT INTO res_occupations1 VALUES ('250', 'biochemical and biotechnical', '5');
INSERT INTO res_occupations1 VALUES ('251', 'biochemical', '5');
INSERT INTO res_occupations1 VALUES ('252', 'biotechnical', '5');
INSERT INTO res_occupations1 VALUES ('253', 'biotechnology', '5');
INSERT INTO res_occupations1 VALUES ('254', 'chemical', '5');
INSERT INTO res_occupations1 VALUES ('301', 'computer integrated manufacturing (CIM)', '6');
INSERT INTO res_occupations1 VALUES ('306', 'computer integrated manufacturing (CIM)', '6');
INSERT INTO res_occupations1 VALUES ('307', 'manufacturing', '6');
INSERT INTO res_occupations1 VALUES ('308', 'fire prevention', '6');
INSERT INTO res_occupations1 VALUES ('310', 'industrial efficiency', '6');
INSERT INTO res_occupations1 VALUES ('311', 'industrial', '6');
INSERT INTO res_occupations1 VALUES ('323', 'ceramics', '7');
INSERT INTO res_occupations1 VALUES ('324', 'coal preparation consulting', '7');
INSERT INTO res_occupations1 VALUES ('325', 'corrosion', '7');
INSERT INTO res_occupations1 VALUES ('337', 'foundry', '7');
INSERT INTO res_occupations1 VALUES ('348', 'consulting mining', '8');
INSERT INTO res_occupations1 VALUES ('349', 'mineral', '8');
INSERT INTO res_occupations1 VALUES ('350', 'mining', '8');
INSERT INTO res_occupations1 VALUES ('364', 'geological', '9');
INSERT INTO res_occupations1 VALUES ('365', 'geophysical', '9');
INSERT INTO res_occupations1 VALUES ('366', 'geotechnical', '9');
INSERT INTO res_occupations1 VALUES ('369', 'supervising - petrography', '9');
INSERT INTO res_occupations1 VALUES ('375', 'drilling, oil and gas', '10');
INSERT INTO res_occupations1 VALUES ('376', 'natural gas', '10');
INSERT INTO res_occupations1 VALUES ('377', 'oil and gas drilling', '10');
INSERT INTO res_occupations1 VALUES ('378', 'petroleum', '10');
INSERT INTO res_occupations1 VALUES ('404', 'aerodynamics', '11');
INSERT INTO res_occupations1 VALUES ('405', 'aeronautical', '11');
INSERT INTO res_occupations1 VALUES ('466', 'capacity planner, network', '12');
INSERT INTO res_occupations1 VALUES ('469', 'capacity planning analyst', '12');
INSERT INTO res_occupations1 VALUES ('470', 'computer (except software)', '12');
INSERT INTO res_occupations1 VALUES ('472', 'computer hardware', '12');
INSERT INTO res_occupations1 VALUES ('474', 'computer systems', '12');
INSERT INTO res_occupations1 VALUES ('477', 'computer telecommunications specialist', '12');
INSERT INTO res_occupations1 VALUES ('487', 'optical communications hardware', '12');
INSERT INTO res_occupations1 VALUES ('489', 'telecommunications hardware', '12');
INSERT INTO res_occupations1 VALUES ('532', 'agricultural', '13');
INSERT INTO res_occupations1 VALUES ('534', 'agronomy', '13');
INSERT INTO res_occupations1 VALUES ('535', 'agroprocessing', '13');
INSERT INTO res_occupations1 VALUES ('538', 'architect, naval', '13');
INSERT INTO res_occupations1 VALUES ('539', 'architect, naval', '13');
INSERT INTO res_occupations1 VALUES ('542', 'bio-resources', '13');
INSERT INTO res_occupations1 VALUES ('544', 'bioelectrical', '13');
INSERT INTO res_occupations1 VALUES ('591', 'application architect', '21');
INSERT INTO res_occupations1 VALUES ('592', 'computer applications', '21');
INSERT INTO res_occupations1 VALUES ('593', 'computer software', '21');
INSERT INTO res_occupations1 VALUES ('594', 'computer telecommunications software specialist', '21');
INSERT INTO res_occupations1 VALUES ('595', 'design, software', '21');
INSERT INTO res_occupations1 VALUES ('596', 'designer, software', '21');
INSERT INTO res_occupations1 VALUES ('597', 'embedded software', '21');
INSERT INTO res_occupations1 VALUES ('598', 'engineer, software', '21');
//-----------------------------End of structure---------------------------------------------------
I want to INSERT the data into another table to get the user_id which comes after login, main category (parent =0), and subcategory (parent <> 0), besides, I need the selected data from listboxes being kept highlighted after submit. How can I do that?
The code to retrieve the data
<?
session_start();
$pagetitle = "Resume Survey";
include 'inc/global.php';
include 'inc/functions.php';
db_conn();
include 'inc/class_page_header.php';
// ---------- INSERT ----------------------------------------------------------
if($action == "insert")
{
if($_POST['flag'] == 1)
{
$valid = TRUE;
if($valid == TRUE)
{
$sql = "INSERT INTO res_user_occupations1 (user_id, id) VALUES ('" . $user_id . "', '" .
$id . "');";
mysql_query($sql);
}
}
}
?>
<script>
var aDetail = new Array();
function categSelected(theSel){
theForm = theSel.form;
opt = theForm.SubCategory.options;
opt.length = 0;
if(theSel.value=="") {
opt[0] = new Option("--Select Subcategory--", "");
return;
}
for(i=0;i<aDetail.length;i++){
if(aDetail[2]==theSel.value){
subCategoryValue = aDetail[1];
for(j=0;j<opt.length;j++){
if(opt[j].value==subCategoryValue) subCategoryValue="";
}
if(subCategoryValue>""){
opt[opt.length] = new Option(subCategoryValue, subCategoryValue);
}
}
}
}
</script>
<form name="joincape" method="post" action="TestonDropdowns.php?action=insert">
<input type="hidden" name="flag" value="1" />
<?php
// database connection ...
$res = mysql_query("SELECT * FROM res_occupations1") or die("Query failed : " . mysql_error());
$i = 0;
$j = 0;
$category_name = array();
$category_value = array();
while($row = mysql_fetch_array($res)) {
if($row['Parent'] == "0") {
$category_value[$j] = $row['id'];
$category_name[$j] = $row['Category'];
$j++;
} // End if loop
?>
<script>
aDetail[<?=$i?>] = new Array();
aDetail[<?=$i?>][0] = "<?=$row['id']?>";
aDetail[<?=$i?>][1] = "<?=$row['Category']?>";
aDetail[<?=$i?>][2] = "<?=$row['Parent']?>";
</script>
<?php
$i++;
} // End while loop
?>
<table>
<TR>
<TD>Category</TD>
<TD colspan="3" >
<select name="Category" onchange="categSelected(this);" >
<option>--Select Category--</option>
<?php
for($t=0; $t<count($category_value); $t++) {
echo "<option value='".$category_value[$t]."'>".$category_name[$t]."</option>";
}
?>
</select>
</TD>
</TR>
<TR>
<TD valign="top" >Sub Categories</TD>
<TD>
<select name="SubCategory">
<option>--Select Subcategory--</option>
</select>
</TD>
</TR>
</table>
<p align="center">
<input type="submit" value="Submit"><br />
<span class="smalltext">[please, press only once]</span>
</p>
</form>