Reputation: 31
Hello I'm looking to get the record and save it to my data base but all the time I'm getting the same sql statement for all the select options
Course ID INSERT INTO `tbl_assign_course` (`course_id_1`, course_id_2`, `course_id_3`) VALUES ('7', '7', '7')
Here is the Options list to choose:
How I can fix this logical error I will appreciate any kind of help
<!DOCTYPE html>
<html>
<head>
<title> The University</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/style.css">
</head>
<body>
<div class="topnav">
<?php $this->load->view('header'); ?>
</div>
<?php
print_r($result);
?>
<form method="post" action="<?php echo(base_url() . "University/std_course_assign/" . $result[0]['course_id'] . "/" . $result[0]['course_i'] . "/" . $result[0]['course_id']); ?>">
<table>
<tr>
<td>
<select name='course_id_1'>
<option value="">--- Select Course ---</option>
<?php
for ($i = 0; $i < count($result); $i++) { ?>
<?php echo "<option value=" . $result[$i]['course_id'] . ">" . $result[$i]['course_name'] . "</option>"; ?>
<?php
}
?>
</td>
<td>
<select name='course_id_2'>
<option value="">--- Select Course ---</option>
<?php
for ($i = 0; $i < count($result); $i++) { ?>
<?php echo "<option value=" . $result[$i]['course_id'] . ">" . $result[$i]['course_name'] . "</option>"; ?>
<?php
}
?>
</td>
<td>
<select name='course_id_3'>
<option value="">--- Select Course ---</option>
<?php
for ($i = 0; $i < count($result); $i++) { ?>
<?php echo "<option value=" . $result[$i]['course_id'] . ">" . $result[$i]['course_name'] . "</option>"; ?>
<?php
}
?>
<input type="hidden" name="std_id" value="<?= $std_id ?>">
<input type="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>
Model Function
public function std_course_assign($course_id) {
$data = array('std_id' => $this->input->post('std_id'),
'course_id_1' => $this->input->post('course_id'),
'course_id_2' => $this->input->post('course_id'),
'course_id_3' => $this->input->post('course_id'),
);
$this->db->insert('tbl_assign_course', $data);
$this->db->where('std_id', $this->input->post('std_id'));
print_r($data);
}
Upvotes: 0
Views: 27
Reputation: 1990
I think You are using WHERE
condition with INSERT
query, use correct INSERT
query for desired result.
and use correct attribute name
in insert query
Upvotes: 0
Reputation: 2025
Your insert query is wrong, change it to 'course_id' to 'course_id_1' 'course_id_2' and so on:
public function std_course_assign($course_id) {
$data= array(
'std_id'=>$this->input->post('std_id'),
'course_id_1'=>$this->input->post('course_id_1'),
'course_id_2'=>$this->input->post('course_id_2'),
'course_id_3'=>$this->input->post('course_id_3')
);
$this->db->insert('tbl_assign_course', $data);
$this->db->where('std_id',$this->input->post('std_id'));
print_r($data);
}
Upvotes: 1