1

我是新手。请帮帮我。我真的很困惑。请帮我。

出现此错误:我不知道我的错误是什么。我是从教程中看到的,他甚至从未犯过任何错误

    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

如果你们能帮助我。这是我的文件:

这是我的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);
}
}

这是我的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>

这是我的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;
}
}
}

}

谢谢大家!

4

1 回答 1

4

user.php中有语法错误

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

这应该是

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

我不确定你为什么在 register() 操作中创建 username_not_exists() 函数

于 2012-11-09T12:11:30.660 回答