警告:mysqli_real_escape_string():无法在第6行的/Applications/XAMPP/xamppfiles/htdocs/try/register.php中获取mysqli
警告:mysqli_real_escape_string():无法在第7行的/Applications/XAMPP/xamppfiles/htdocs/try/register.php中获取mysqli
警告:mysqli_real_escape_string():无法在第8行的/Applications/XAMPP/xamppfiles/htdocs/try/register.php中获取mysqli
警告:mysqli_real_escape_string():无法在第9行的/Applications/XAMPP/xamppfiles/htdocs/try/register.php中获取mysqli
警告:mysqli_query():无法在第12行的/Applications/XAMPP/xamppfiles/htdocs/try/register.php中获取mysqli
REGISTER.PHP
<?php
$output=NULL;
if (isset($_POST['submit'])) {
include 'config.php';
$name = mysqli_real_escape_string($conn, $_POST['name']); //this is LINE 6
$email = mysqli_real_escape_string($conn, $_POST['email']); // LINE 7
$username = mysqli_real_escape_string($conn, $_POST['username']); //LINE 8
$password = mysqli_real_escape_string($conn, $_POST['password']); //LINE 9
$query= "SELECT * FROM users WHERE username= '$username'";
$result= mysqli_query($conn, $query); //LINE 12
if (empty($name) || empty($email) || empty($username) || empty($password)) {
$output= "please all the fields";
} elseif (mysqli_num_rows($result)!=0) {
$output= 'the username is already taken';
} elseif (strlen($password)<8) {
$output= "your must be atleast 8 characters";
} else {
// insert the record.
$insert = mysqli_query($conn, "INSERT INTO users(name, email, username, password)
VALUES ('$name', '$email', '$username', '$password')");
if ($insert != TRUE) {
$output= 'there was a problem '. mysqli_error();
} else {
$output= "record was successfully created " ;
}
}
}
/*if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['username']) && isset($_POST['password'])){
$name = $_POST['name'];
$email = $_POST['email'];
$username=$_POST['username'];
$password = $_POST['password'];
$query= "INSERT INTO users (name, email, username, password
VALUES ('{$name}', '{$email}', '{$username}', '{$password}')";
$result = mysqli_query($conn, $query);
if ($result) {
echo "user created successfuly.";
} else {
die ("user registeration failed".mysqli_error());
}
}*/
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>testing site</title>
</head>
<body>
<form method="POST">
<table>
<p>Fill the Registration form below</p>
<tr>
<td>Name: </td>
<td> <input type="name" name="name" > </td>
</tr>
<tr>
<td>Email: </td>
<td> <input type="email" name="email"> </td>
</tr>
<tr>
<td>Username: </td>
<td><input type="text" name="username"> </td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password"> </td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Register">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
</body>
</html>
CONFIG.PHP
<?php
$server='localhost';
$dbuser='root';
$dbpass="";
$dbname="testing";
$conn =mysqli_connect($server,$dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()) {
die ("database connection failed"
. mysqli_connect_error());
}
mysqli_close($conn);
?>