我已经检查了其他答案并尝试将其复制到我的答案中,但我收到了一个未经识别的row
错误。
<?php
session_start();
if(isset($_SESSION['user_id'])) {
header("Location: index.php");
}
include_once 'dbconnect.php';
//set validation error flag as false
$error = false;
//check if form is submitted
if (isset($_POST['signup'])) {
$first_name = mysqli_real_escape_string($con, $_POST['first_name']);
$last_name = mysqli_real_escape_string($con, $_POST['last_name']);
$username = mysqli_real_escape_string($con, $_POST['username']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$cpassword = mysqli_real_escape_string($con, $_POST['cpassword']);
$quote = mysqli_real_escape_string($con, $_POST['quote']);
$who = mysqli_real_escape_string($con, $_POST['who']);
//name can contain only alpha characters and space
if ($_POST['username'] == $row['username']){
$error = true;
$username_error = '<div class="error-notice">
<div class="oaerror danger">
<strong>Uh oh!</strong> - Username is already in use.
</div>';
}
答案 0 :(得分:0)
没关系,我明白了。我必须在我的代码之上执行此操作。
$result = mysqli_query($con, "SELECT * FROM users WHERE username = '" . $username. "'");
if($row = mysqli_fetch_array($result)){