Little database problem
Hi am working on a seat reservation project. I am making this project in code_igniter. Now I have a little problem with sending the seat label through the database. In my proj开发者_Python百科ect there is a little JQuery part. When I check a checkbox, the name will be placed on a label. But when I send it to the database it always returns 0 ???
This is my jquery function.
$('[name=check]').each(function(i,d){
$(d).removeAttr('disabled');
});
}
$("#seatDiv").html($(this).val());
$(document).ready(function() {
$("input[name=check]").change(function() {
$("#seatDiv").html($(this).val());
})
});
My form
echo form_open('user/register');
$username = array(
'name' => 'reg_username',
'id' => 'reg_username',
'value' => set_value('reg_username')
);
$email = array(
'name' => 'reg_email',
'id' => 'reg_email',
'value' => set_value('reg_email')
);
$gsmnummer = array(
'name' => 'reg_gsmnummer',
'id' => 'reg_gsmnummer',
'value' => set_value('reg_gsmnummer')
);
$zitplaats = array(
'name' => 'reg_zitplaats',
'id' => 'reg_zitplaats',
'value' => '$id'
);
?>
<table>
<tr>
<td><label> Naam </label></td>
<td> <div> <?php echo form_input($username); ?></div></td>
</tr>
<tr>
<td><label>e-mail </label></td>
<td><div> <?php echo form_input($email); ?></div></td>
</tr>
<tr>
<td><label> gsm-nummer </label></td>
<td><div> <?php echo form_input ($gsmnummer); ?> </div></td>
</tr>
<tr>
<td><label>zitplaats</label></td>
<td><div id="seatDiv" > <?php echo form_label($id='seatDiv'); ?> </div></td>
</tr>
<tr>
<td> <?php echo form_submit(array('name'=> 'verzend','value' => 'verzend')); ?> </td>
<?php echo form_close(); ?>
And my user_model
class User_model extends Model{
function User_model() {
parent :: Model() ;
}
function register_user($username, $email, $gsmnummer, $zitplaats){
$query_str ="INSERT INTO tbl_reservering (username,gsmnummer,email,zitplaats)VALUES(?, ?, ?, ?)";
$this->db->query($query_str,array($username,$email,$gsmnummer,$zitplaats));
}
}
Hope anyone can help me!
thank you!
$zitplaats = array(
'name' => 'reg_zitplaats',
'id' => 'reg_zitplaats',
'value' => '$id'
);
Variables aren't parsed when they are in single quotes.
and where is $id
being set from.
<tr>
<td><label>zitplaats</label></td>
<td><div id="seatDiv" > <?php echo form_label($id='seatDiv'); ?> </div></td>
you also aren't even using $zitplaats
in your code.
I'm not sure what form_label($id='seatDiv')
is doing either, doesn't look right to me.
What's the output?
You could include a hidden input that contains the value you want to pass to the controller (and ultimately the model). Ensure that your controller is set up to retrieve 'reg_zitplaats'.
Your jQuery should look something like this (I've made some modifications to your original post as it was doing some really strange stuff):
$(function() {
$('input[name=check]').removeAttr('disabled'); // not sure why the checkbox is disabled to start off with
$('input[name=check]').change(function() {
$('#seatDiv').html($(this).val());
$('#reg_zitplaats').val($(this).val());
});
});
Then, your html can be as so (notice the hidden input):
<?php
echo form_open('user/register');
$username = array(
'name' => 'reg_username',
'id' => 'reg_username',
'value' => set_value('reg_username')
);
$email = array(
'name' => 'reg_email',
'id' => 'reg_email',
'value' => set_value('reg_email')
);
$gsmnummer = array(
'name' => 'reg_gsmnummer',
'id' => 'reg_gsmnummer',
'value' => set_value('reg_gsmnummer')
);
$zitplaats = array(
'name' => 'reg_zitplaats',
'id' => 'reg_zitplaats',
'value' => $id
);
?>
<table>
<tr>
<td><label>Naam</label></td>
<td>
<div>
<?php echo form_input($username); ?>
</div>
</td>
</tr>
<tr>
<td><label>e-mail </label></td>
<td>
<div>
<?php echo form_input($email); ?>
</div>
</td>
</tr>
<tr>
<td><label>gsm-nummer</label></td>
<td>
<div>
<?php echo form_input($gsmnummer); ?>
</div>
</td>
</tr>
<tr>
<td><label>zitplaats</label></td>
<td>
<?php echo form_hidden($zitplaats); ?>
<div id="seatDiv" >
<?php echo form_label($id='seatDiv'); ?>
</div>
</td>
</tr>
<tr>
<td><?php echo form_submit(array('name'=> 'verzend','value' => 'verzend')); ?></td>
</tr>
</table>
<?php echo form_close(); ?>
Try this out and let us know how you go.
精彩评论