Hey there Im tring to insert to a database from a form , however I cant get it to insrt with the dropdwon list, any help would be loved

<h1>Insert Data Into Database Using CodeIgniter</h1>
<?php echo form_label('lecturer_id:'); ?> <?php echo form_error('dname'); ?>
<?php echo form_input(array('id' => 'dname', 'name' => 'dname')); ?>
<?php echo form_label('subject_id :'); ?> <?php echo form_error('demail'); ?>
<?php echo form_input(array('id' => 'demail', 'name' => 'demail')); ?>
<?php echo form_label('coarse_name :'); ?> <?php echo form_error('dmobile'); ?>
<?php echo form_input(array('id' => 'dmobile', 'name' => 'dmobile')); ?>
<?php echo form_label('Coarse_description :'); ?> <?php echo form_error('daddress'); ?>


<select name="daddress">
<?php $sql = "select id, email from coarse_lecturers ";
$result = mysql_query($sql);
echo "<select name='id'><option value=''>Please Select  </option>";
while ($row = mysql_fetch_array($result)){
Im tring to remember what is selected then add it to a table
    echo"<option value = '" . $row['id'] . "'>" . $row['email'] . "</option>";
    array('id' => 'daddress', 'value' => 'daddress');


}
echo "</select>";

?>
<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit'));?>
<?php echo form_close(); ?>

all good now , got it inserting
Something soo small , heres the way if anyobe needs help, or if anybody can see any issues aswell

<html>
<head>
<title>Insert Data Into Database Using CodeIgniter Form</title>
<link href='http://fonts.googleapis.com/css?family=Marcellus' rel='stylesheet' type='text/css'/>
<link rel="stylesheet" type="text/css" href="http://localhost/CodeIgniter/css/styles.css"/>
</head>
<body>
<div id="container">
<?php echo form_open('insert_ctrl/error'); ?>
<h1>Insert Data Into Database Using CodeIgniter</h1>
<?php echo form_label('lecturer_id:'); ?> <?php echo form_error('dname'); ?>
<?php echo form_input(array('id' => 'dname', 'name' => 'dname')); ?>
<?php echo form_label('subject_id :'); ?> <?php echo form_error('demail'); ?>
<?php echo form_input(array('id' => 'demail', 'name' => 'demail')); ?>
<?php echo form_label('coarse_name :'); ?> <?php echo form_error('dmobile'); ?>
<?php echo form_input(array('id' => 'dmobile', 'name' => 'dmobile')); ?>
<?php echo form_label('Coarse_description :'); ?> <?php echo form_error('daddress'); ?>
<select name="daddress">
<option value="none" selected="selected">------------Select Lecturer------------</option>

<?php $sql = "select id, email from coarse_lecturers ";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)){


    echo"<option value = '" . $row['id'] . "'>" . $row['email'] . "</option>";




    array('id' => 'daddress', 'value' => 'daddress');


}
echo "</select>";

?>
<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit'));?>
<?php echo form_close(); ?>
</div>
</body>
</html>

you should put your database functions or procedure in a model. Use the controller to handle the input and output.

Example for your select dropdown.

lecture_model.php

<?php if( !defined('BASEPATH') ){exit("No direct script access allowed!");}

class Lecture_Model extends CI_Controller {

    public function get_coarse_information()
    {
        $this->db->select('id, email');
        $this->db->from('course_lecturers');

        $query = $this->db->get();

        if($query->num_rows() > 0){
            return $query->results_array();
        }else{
            return false;
        }
    }



}

The data gets passed to the view in the controller

$data['coarse_information'] = $this->lecture_model->get_coarse_information();

$this->load->view('template', $data);

create loop in the view.

<select name="">
<option></option>
<?php foreach($coarse_information as $info): ?>
<option value="<?php echo $info['id']; ?>"><?php echo $info['email']; ?></option>
<?php endforeach; ?>
</select>

Hey there ,

Im using Codiegniter and have it insrting with the help of a model and controller to handle from errors.

Thanks though

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.