count_all () or count_all_results ()? - El Forum - 01-07-2011
[eluser]domix24[/eluser]
hello,
I type this in the url (localhost/codeigniter/registration/registration/) I see well the form I type words in the corresponding fields (username = domix24 pass = ******** pass2 = ******** [email protected]) (these fields of are not in the database) I confirm the form and I see these figures: 00 wants to means(false for the email and false for the username). If I put count_all () for 2, it shows me 11 well, but if I test data which are in the database (username = domix24 and email = [email protected]) (I vien to enter them with the script) I also obtain 11 and it reinsert in the database. You have an idea of which to put between count_all () (just insertions in the database) and count_all_result () (no insertion in the database)?
thank you.
If you do not want (or can not) download the file, consider lower in the page
count_all () or count_all_results ()? - El Forum - 01-07-2011
[eluser]domix24[/eluser]
Is he a person to solve my problem?
count_all () or count_all_results ()? - El Forum - 01-08-2011
[eluser]Atharva[/eluser]
You will get reply more quickly if you post your code here instead of attaching a file.
count_all () or count_all_results ()? - El Forum - 01-08-2011
[eluser]domix24[/eluser]
registery.php
Code: <?php
class Registery extends Controller{
public function __construct() {
parent::Controller();
$this->load->library('form_validation');
}
public function index(){
$this->inscription();
}
public function inscription(){
$this->form_validation->set_rules('user', 'Username', 'required|trim|min_length[3]|max_length[15]|alpha_dash|xss_clean|encode_php_tags');
$this->form_validation->set_rules('pass1', 'Password', 'required|trim|min_length[3]|max_lenght[15]|matches[mdp2]|xss_clean');
$this->form_validation->set_rules('pass2', 'password confirm', 'required|trim|min_length[3]|max_lenght[15]|matches[mdp2]|xss_clean');
$this->form_validation->set_rules('email', 'email adress', 'required|trim|valid_email|xss_clean');
if($this->form_validation->run() == FALSE)
$this->load->view('form');
else{
$this->load->model('registery_model', 'registery');
$data = array();
$data['user'] = $this->registery->isValidUser($this->input->post('user'));
$data['pass1'] = sha1($this->input->post('pass1'));
$data['pass2'] = sha1($this->input->post('pass2'));
$data['email'] = $this->registery->isValideMail($this->input->post('email'));
$data['valid'] = $this->registery->goToSubmit($data['pseudo'], $data['email']);
$bigArray = array(
'user' => $this->input->post('user'),
'password' => $data['pass1'],
'passwordc' => $data['pass2'],
'email' => $this->input->post('email'));
$data['d'] = $this->inscriptionModel->insertData($data['valid'], $bigArray);
$this->load->view('formgood', $data);
}
}
}
?>
registery_model.phpCode: <?php
class Registery_model extends Model{
private $table = 'users';
public function isValidUser($username){
$this->load->database();
if(!empty($username)){
if(is_string($username)){
$this->db->select('user')->from($this->table)->where('user', $username)->get()->result();
if($this->db->count_all_results() == 0){
if($this->db->count_all() == 0){
return 1;
}
else{
return 2;
}
}else{
if($this->db->count_all() == 0){
return 3;
}
else{
return 4;
}
}
}else{
return false;
}
}else{
return false;
}
}
public function isValideMail($email){
$this->load->database();
if(!empty($email)){
$this->db->select('email')->from($this->table)->where('email', $email)->get()->result();
if($this->db->count_all_results() == 0){
if($this->db->count_all() == 0){
return 1;
}else{
return 2;
}
}else{
if($this->db->count_all() == 0){
return 3;
}else{
return 4;
}
}
}else{
return false;
}
}
public function goToSubmit($a = true){
$a = func_get_args();
if($a[0] && $a[1]){
return true;
}
else{
return false;
}
}
function insertData($v, $var = array()){
$this->load->database();
if($v){
$this->db->insert($this->table, $var);
return true;
}
else{
return false;
}
}
//no / 0 = false
//yes / 1 = true
}
?>
form.phpCode: <html>
<head>
<title>My Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $this->config->item('charset'); ?>" />
</head>
<body>
<p>
Registery system
</p>
<form method="post" action="">
<p>
<label for="pseudo">Username </label>
<input type="text" name="user" value="<?php echo set_value('user'); ?>" /><?php echo form_error('user'); ?><br />
<span id="passtitle">Password</span><br />
<label for="mdp1">Mot de passe voulu : </label>
<input type="password" name="pass1" value="<?php echo set_value('pass1'); ?>" /><?php echo form_error('pass1'); ?><br />
<label for="mdp2">Confirmation du mot de passe</label>
<input type="password" name="pass2" value="<?php echo set_value('pass2'); ?>" /><?php echo form_error('pass2'); ?><br /><br />
<label for="mail">Votre adresse mail</label>
<input type="text" name="email" value="<?php echo set_value('email'); ?>" /><?php echo form_error('email'); ?><br /><br />
<input type="submit" value="Submit!" />
</p>
</form>
</body>
</html>
formgood.phpCode: <html>
<head>
<title>form validation</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $this->config->item('charset'); ?>" />
</head>
<body>
<?php
echo $mail;
echo $pseudo;
?>
</body>
</html>
count_all () or count_all_results ()? - El Forum - 01-08-2011
[eluser]cideveloper[/eluser]
Hello Domix
Right of the bat there are some glaring problems from the code you showed here.
Code: <label for="pseudo">Username </label>
<input type="text" name="user" value="<?php echo set_value('user'); ?>" /><?php echo form_error('user'); ?><br />
The label says for="pseudo" while the field has a name="user"
The same issue for all your fields and labels
Secondly
Code: $this->form_validation->set_rules('pass1', 'Password', 'required|trim|min_length[3]|max_lenght[15]|matches[mdp2]|xss_clean');
$this->form_validation->set_rules('pass2', 'password confirm', 'required|trim|min_length[3]|max_lenght[15]|matches[mdp2]|xss_clean');
matches[mdp2] is nothing. You are not sending mdp2 in the form.
Code: $data['valid'] = $this->registery->goToSubmit($data['pseudo'], $data['email']);
$data['pseudo'] is nothing. It is not set in the controller.
IMPORTANT
look into Callbacks instead of
Code: $data['user'] = $this->registery->isValidUser($this->input->post('user'));
$data['email'] = $this->registery->isValideMail($this->input->post('email'));
Then you wont have to go through the process of goToSubmit
Also why are you storing pass2 in the db? Its only meant to be a confirmation to make sure they typed the password correct.
Also if you don't want duplicates in the db for specifi fields you should have a unique constraint on the fields.
count_all () or count_all_results ()? - El Forum - 01-08-2011
[eluser]domix24[/eluser]
Thank you, I fix all problems and works! ;-)
I did not know the trick of "callback" :bug:
|