简体   繁体   English

使用Codeigniter进行验证编码注册表的麻烦

[英]Trouble with coding Registration Form with Validation using Codeigniter

I'm new at using this. 我是新手使用它。 Help me please. 请帮帮我。 I am really confused. 我真的很困惑。 Please help me. 请帮我。

This error is appearing: I dont know what my mistake is. 这个错误出现了:我不知道我的错误是什么。 I saw it from a tutorial and he never even made any error 我从教程中看到它,他甚至从未犯过任何错误

    Parse error: syntax error, unexpected '(', expecting T_STRING or 
    T_VARIABLE or '{' or '$' in 
    C:\xampp\htdocs\test\application\controllers\user.php on line 50

If you guys can help me. 如果你们可以帮助我。 Here are my files: 这是我的文件:

this is my user.php 这是我的user.php

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

    class User extends CI_Controller {
     private $view_data = array();
function _construct()
{
parent::_construct();
$this->view_data['base_url']=base_url();
}

function index()
{
$this->register();
}

function register()
{
$this->load->library('form_validation');

$this->form_validation->set_rules('firstname', 'First Name', 'trim|required|max_length[100]|min_length[1]|xss_clean');
$this->form_validation->set_rules('lastname', 'Last Name', 'trim|required|max_length[100]|min_length[1]|xss_clean');
$this->form_validation->set_rules('email', 'Email Address', 'trim|required|max_length[100]|xss_clean|valid_email');
$this->form_validation->set_rules('dateofbirth', 'Date of Birth', 'trim|max_length[100]|min_length[1]|xss_clean');
$this->form_validation->set_rules('gender', 'Gender', 'trim|max_length[6]|min_length[6]|xss_clean');
$this->form_validation->set_rules('username', 'User Name', 'trim|required|alpha_numeric|callback_username_not_exists|max_length[100]|min_length[6]|xss_clean'); 


if ($this->form_validation->run() == FALSE)
{
//not run
$this->load->view('view_register', $this->view_data);

}
else
{
//good
$firstname=$this->input->post('firstname'); 
$lastname=$this->input->post('lastname');
$email=$this->input->post->('email');
$dateofbirth=$this->input->post('dateofbirth');
$gender=$this->input->post('gender');
$username=$this->input->post('username');
$password=$this->input->post('password');

$this->User_model->register_user($firstname, $lastname, $email, $dateofbirth, $gender, $username, $password);

function username_not_exists($username){
$this->form_validation->set_message('username_not_exists','the username %s is existing');
if($this->User_model->check_exists_username($username))
{
return false;
}
else
{
return true;
}
}

}
$this->load->view('view_register', $this->view_data);
}
}

This is my view_register.php 这是我的view_register.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Registration</title>

<style type="text/css">

::selection{ background-color: #E13300; color: white; }
::moz-selection{ background-color: #E13300; color: white; }
::webkit-selection{ background-color: #E13300; color: white; }

body {
    background-color: #fff;
    margin: 40px;
    font: 13px/20px normal Helvetica, Arial, sans-serif;
    color: #4F5155;
}

a {
    color: #003399;
    background-color: transparent;
    font-weight: normal;
}

h1 {
    color: #444;
    background-color: transparent;
    border-bottom: 1px solid #D0D0D0;
    font-size: 19px;
    font-weight: normal;
    margin: 0 0 14px 0;
    padding: 14px 15px 10px 15px;
}

code {
    font-family: Consolas, Monaco, Courier New, Courier, monospace;
    font-size: 12px;
    background-color: #f9f9f9;
    border: 1px solid #D0D0D0;
    color: #002166;
    display: block;
    margin: 14px 0 14px 0;
    padding: 12px 10px 12px 10px;
}

#body{
    margin: 0 15px 0 15px;
}

</style>
</head>
<body>


<h1>IMAGE HERE</h1>

<div id="body">
    <br/>

    <p class="body">

    <?php
    echo form_open('start');
    $firstname = array(
    'name'  =>  'firstname',
    'value' =>  set_value('firstname')
    );

    $lastname = array(
    'name'  =>  'lastname',
    'value' =>  set_value('lastname')
    );

    $email = array(
    'name'  =>  'email',
    'value' =>  set_value('email')
    );

    $dateofbirth = array(
    'name'  =>  'dateofbirth',
    'value' =>  set_value('dateofbirth')
    );

    $gender = array(
    'name'  =>  'gender',
    'value' =>  set_value('gender'),
    'style' =>  'margin:10px'
    );

    $username = array(
    'name'  =>  'username',
    'value' =>  set_value('username')
    );

    $password = array(
    'name'  =>  'password',
    'value' =>  ''
    );

    $confpass = array(
    'name'  =>  'confpass',
    'value' =>  ''
    );


    ?>


    <strong>User Information: </strong>
    &nbsp;
    <div align="right"><font color="red">*</font>Denotes Required Field</div>

    <div align="left">
    First Name<font color="red">*</font>:
    <?php echo form_input($firstname)?>
    <br/>

    Last Name<font color="red">*</font>:
    <?php echo form_input($lastname)?>
    <br/>

    Email Address<font color="red">*</font>:
    <?php echo form_input($email)?>
    <br/>

    Date Of Birth:
    <?php echo form_input($dateofbirth)?>
    <br/>

    Gender:
        <?php 
        echo form_radio($gender, 'Male');
        echo "Male";
        echo form_radio($gender, 'Female'); 
        echo "Female";
        ?>
        <br/>



    <strong>Account Information:</strong><br/>


    Username<font color="red">*</font>:
    <?php echo form_input($username)?><br/>

    Password<font color="red">*</font>:
    <?php echo form_password($password)?><br/>

    Password Confirmation<font color="red">*</font>:
    <?php echo form_password($confpass)?><br/>

    <?php 
    echo validation_errors();?>
    <?php echo form_submit(array('name'=>'register'), 'Register');?>
    <?php echo form_reset(array('name'=>'reset'), 'Reset')?>

</div>

</body>
</html>

And this is my code for usermodel.php 这是我的usermodel.php代码

<?php


class User_model extends CI_Model {
function User_model() {
parent::Model();
}
function register_user($firstname, $lastname, $email, $dateofbirth, $gender, $username, $password)
{
$sha1_password=sha1($password);
$query_str="INSERT INTO tbl_user(firstname, lastname, email, dateofbirth, gender, username, password) VALUES (?,?,?,?,?,?,?)";

$this->db->query-($query_str, array($firstname, $lastname, $email, $dateofbirth, $gender, $username, $sha1_password));

function check_exists_username($username)
{
$query_str = "SELECT username FROM tbl_user WHERE username = ?";
$result=$this->db->query->($query_str, $username);
if($result -> num_rows() > 0)
{
return true;
}
else
{
return false;
}
}
}

}

Thank you all in advance! 谢谢大家!

there is a syntax error in user.php user.php中存在语法错误

$email=$this->input->post->('email');

This should be 这应该是

$email=$this->input->post('email');

I'm not sure why did you create username_not_exists() function inside register() action 我不确定你为什么在register()动作中创建username_not_exists()函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM