Reputation: 37
job_category{
category_id PRIMARY KEY,
category_name
}
job{
job_id PRIMARY KEY,
role
category_id FOREIGN KEY
}
exam{
exam_id AUTO INCREMENT PRIMARY KEY,
exam_name,
job_cat
}
//job_cat is con-cat value as job_id-category_id
This is my select option
<select name="job_cat" id="select_item" required="true">
<option value="">Select the Job Role</option>
<?php
$sql1="SELECT Cat.category_id category_id, Cat.category_name category_name, Job.job_id job_id, Job.role role FROM job Job LEFT JOIN job_category Cat ON Job.category_id=cat.category_id";
$result1= mysqli_query($dbcon, $sql1);
while($row1=mysqli_fetch_array($result1)){?>
<option value="<?php echo $row1["job_id"] . "-" . $row1["catergory_id"]; ?>"><?php echo $row1["role"] . " - " . $row1["catergory_name"] ;?></option>
<?php }?>
</select>
//insert values
$exam_name=$_POST['exam_name'];
$job_cat=$_POST['job_cat'];
$sql2= "INSERT INTO exam_paper (exam_name,job_cat) VALUES ('$exam_name','$job_cat')";
this is not work properly. Ths insert only the job_id into the 'job_cat' column. category_id not added. how can I fix it
Upvotes: 0
Views: 47
Reputation: 269
this will insert your data just put your column name instead of column_name
$job_cat=$_POST['job_cat'];
$ins=mysqli_query("insert into column_name values ('".$job_cat."')");
if($ins)
{echo "data inserted";}
else
{echo "data not inserted";}
Upvotes: 1
Reputation: 269
in your table replace job category
with job_category
and your insert query with
INSERT INTO exam_paper (`exam_name`,`job_cat`) VALUES ('".$exam_name."','".$job_cat."')
Upvotes: 1