<!DOCTYPE html>
<html>
<head>
<title>User Registration</title>
</head>
<body>
<!--Design area-->
<a href="register.php">Register</a><=====><a href="login.php">Login</a>
<h3>Registration Form</h3>
<form action="" method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" name="register" value="Register">
</form>
<!--End design area-->
<!--PHP Section-->
<?php
if(isset($_POST['register'])){
$username=$_POST['username'];
$password=$_POST['password'];
$con=mysqli_connect('localhost','root','','log') or die("Connection failure");
$query="SELECT * FROM log_data WHERE username='".$username."'";//Validation query
$run_query=mysqli_query($con,$query);
$row_count=mysqli_num_rows($run_query);
Bis jetzt funktioniert alles. Aber als ich die row count-Bedingung gab und dann schreibe einfügen Abfrage, zu diesem Zeitpunkt Browser sagt Konto nicht erstellt. Das bedeutet, dass meine Abfrage nicht ausgeführt wird. Warum?Warum diese Einfügeabfrage nicht funktioniert?
if($row_count==0){
$query="INSERT INTO log_data(username,password) VALUES('$username','$password')";//insert query
$run_query=mysqli_query($con,$query);
if($run_query){//if inserted
echo "Account Successfully Created";
} else {
echo "Account not created";
}
}else{
echo "This username already exits";
}
}
?>
<!--End Php Section-->
</body>
</html>
Ihr Code auf SQL-Injektionen anfällig ist. Bitte lernen Sie [vorbereitete Aussagen] (https://www.youtube.com/watch?v=nLinqtCfhKY). Auch das Speichern von Passwörtern als Klartext-String ist eine schreckliche Idee. –
mysqli_num_rows ($ query); –
$ row_count = $ query-> num_rows; –