我在下面编写了代码,但看到了未定义的变量问题:
此代码中有2个文件。一个文件用于登录,另一个文件用于类。关于创建和登录页面。注册不是问题,它可以正常工作,但是当我想在现有登录名中注册时,我会遇到问题。他们告诉了未定义变量问题。
login.php(file name)
<?php include "inc/header.php"; ?>
<?php
$cmr = new Customer();
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['login'])) {
$custLogin = $cmr->customerLogin($_POST);
}
?>
<div class="main">
<div class="content">
<div class="login_panel">
<?php
if (isset($custLogin)) {
echo $custLogin;
}
?>
<h3>Existing Customers</h3>
<p>Sign in with the form below.</p>
<form action="" method="post">
<input name="email" placeholder="Enter your email" type="text"/>
<input name="pass" placeholder="Enter your password" type="password"/>
<p class="note">If you forgot your passoword just enter your email and click <a href="#">here</a></p>
<div class="buttons"><div><button class="grey" name="login">Sign In</button></div></div>
</div>
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['register'])) {
$customerReg = $cmr->customerRegistration($_POST);
}
?>
<div class="register_account">
<?php
if (isset($customerReg)) {
echo $customerReg;
}
?>
<h3>Register New Account</h3>
<form action="" method="post">
<table>
<tbody>
<tr>
<td>
<div>
<input type="text" name="name" placeholder="Name"/>
</div>
<div>
<input type="text" name="city" placeholder="City"/>
</div>
<div>
<input type="text" name="zip" placeholder="Zip-Code"/>
</div>
<div>
<input type="text" name="email" placeholder="Email"/>
</div>
</td>
<td>
<div>
<input type="text" name="address" placeholder="Address"/>
</div>
<div>
<input type="text" name="country" placeholder="Country"/>
</div>
<div>
<input type="text" name="phone" placeholder="Phone"/>
</div>
<div>
<input type="text" name="pass" placeholder="Password"/>
</div>
</td>
</tr>
</tbody></table>
<div class="search"><div><button class="grey" name="register">Create Account</button></div></div>
<p class="terms">By clicking 'Create Account' you agree to the <a href="#">Terms & Conditions</a>.</p>
<div class="clear"></div>
</form>
</div>
<div class="clear"></div>
</div>
</div>
<?php include "inc/footer.php"; ?>
//////////////////////////////////////////////////
Customer.php (file name)
/////////////////////////////////////////////////
<?php
$filepath = realpath(dirname(__FILE__));
include_once ($filepath."/../lib/Database.php");
include_once ($filepath."/../helpers/Format.php");
?>
<?php
class Customer{
private $db;
private $fm;
public function __construct(){
$this->db = new Database();
$this->fm = new Format();
}
public function customerRegistration($data){
$name = $this->fm->validation($data['name']);
$address = $this->fm->validation($data['address']);
$city = $this->fm->validation($data['city']);
$country = $this->fm->validation($data['country']);
$zip = $this->fm->validation($data['zip']);
$phone = $this->fm->validation($data['phone']);
$email = $this->fm->validation($data['email']);
$pass = $this->fm->validation($data['pass']);
$name = mysqli_real_escape_string($this->db->link, $data['name']);
$address = mysqli_real_escape_string($this->db->link, $data['address']);
$city = mysqli_real_escape_string($this->db->link, $data['city']);
$country = mysqli_real_escape_string($this->db->link, $data['country']);
$zip = mysqli_real_escape_string($this->db->link, $data['zip']);
$phone = mysqli_real_escape_string($this->db->link, $data['phone']);
$email = mysqli_real_escape_string($this->db->link, $data['email']);
$pass = mysqli_real_escape_string($this->db->link, md5($data['pass']));
if ($name == "" || $address == "" || $city == "" || $country == "" || $zip == "" || $phone == "" || $email == "" || $pass == ""){
$msg = "<span class='error'>Field must not be empty !</span>";
return $msg;
}
$mailquery = "select * from tbl_customer where email='$email' limit 1";
$mailchk = $this->db->select($mailquery);
if ($mailchk != false) {
$msg = "<span class='error'>Email already exist!</span>";
return $msg;
} else {
$query = "insert into tbl_customer(name,address,city,country,zip,phone,email,pass)
values ('$name','$address','$city','$country','$zip','$phone','$email','$pass')";
$userinsert = $this->db->insert($query);
if ($userinsert) {
$msg = "<span class='success'>Customer Data Added Successfully !</span>";
return $msg;
} else {
$msg = "<span class='error'>Customer Data not added !</span>";
return $msg;
}
}
}
public function customerLogin($date){
$email = $this->fm->validation($data['email']);
$pass = $this->fm->validation($data['pass']);
$email = mysqli_real_escape_string($this->db->link, $data['email']);
$pass = mysqli_real_escape_string($this->db->link, md5($data['pass']));
if (empty($email) || empty($pass)) {
$msg = "<span class='error'>Field must not be empty !</span>";
return $msg;
}
$query = "select * from tbl_customer where email = '$email' AND pass = '$pass'";
$result = $this->db->select($query);
if ($result != false) {
$value = $result->fetch_assoc();
Session::set("cuslogin",true);
Session::set("cmrId",$value['id']);
Session::set("cmrName",$value['name']);
header("Location:order.php");
} else {
$msg = "<span class='error'>Email or Password doesnot match!</span>";
return $msg;
}
}
}
?>
公共功能customerLogin($ date){ $ email = $ this-> fm-> validation($ data ['email']); $ pass = $ this-> fm-> validation($ data ['pass']);
$email = mysqli_real_escape_string($this->db->link, $data['email']);
$pass = mysqli_real_escape_string($this->db->link, md5($data['pass']));
这4行我遇到了一个问题,问题在下面:
注意:未定义的变量:第60行的D:\ xampp \ htdocs \ shop \ classes \ Customer.php中的数据
注意:未定义的变量:第61行的D:\ xampp \ htdocs \ shop \ classes \ Customer.php中的数据
注意:未定义的变量:第63行的D:\ xampp \ htdocs \ shop \ classes \ Customer.php中的数据
注意:未定义的变量:第64行的D:\ xampp \ htdocs \ shop \ classes \ Customer.php中的数据
答案 0 :(得分:0)
第59行-O型
更改此
public function customerLogin($date){
到
public function customerLogin($data){