运行php代码时出现以下错误。我正在尝试创建注册表单,但它始终显示以下错误消息。
解析错误:语法错误,意外的'$ username'(T_VARIABLE),期待第15行/home/xxx/public_html/dashboard.php中的']'
请帮我解决这个问题
<?php
session_start();
require 'config.php';
if (isset($_POST['register_btn])){
session_start();
$username = mysql_real_escape_string($_POST["username"]);
$firstName = mysql_real_escape_string($_POST["firstName"]);
$lastName = mysql_real_escape_string($_POST["lastName"]);
$email = mysql_real_escape_string($_POST["email"]);
$password = mysql_real_escape_string($_POST["password"]);
$password2 = mysql_real_escape_string($_POST["password2"]);
if ($password == $password2){
$password = md5($password);
$sql = "INSERT INTO users(username, firstName, lastName, email, password, password2)
VALUES('$username', '$firstName', '$lastName', '$email', '$password', '$password2')";
mysqli_query($conn, $sql);
$_SESSION['message'] = "You are successfully logged in";
$_SESSION['firstName'] = $firstName;
$_SESSION['lastName'] = $lastName;
}else {
$_SESSION['message'] = "The Two password do not match";
}
}
?>
答案 0 :(得分:-1)
您忘记关闭'
中的单引号if (isset($_POST['register_btn'])){
。
运行以下代码。
<?php
session_start();
require 'config.php';
if (isset($_POST['register_btn'])){
session_start();
$username = mysql_real_escape_string($_POST["username"]);
$firstName = mysql_real_escape_string($_POST["firstName"]);
$lastName = mysql_real_escape_string($_POST["lastName"]);
$email = mysql_real_escape_string($_POST["email"]);
$password = mysql_real_escape_string($_POST["password"]);
$password2 = mysql_real_escape_string($_POST["password2"]);
if ($password == $password2){
$password = md5($password);
$sql = "INSERT INTO users(username, firstName, lastName, email, password, password2)
VALUES('$username', '$firstName', '$lastName', '$email', '$password', '$password2')";
mysqli_query($conn, $sql);
$_SESSION['message'] = "You are successfully logged in";
$_SESSION['firstName'] = $firstName;
$_SESSION['lastName'] = $lastName;
}else {
$_SESSION['message'] = "The Two password do not match";
}
}
?>