0
HTML coding problem
I have a code which i wrote for a gane im designing but im stuck at the registration screen because i can register myself as admin but for some reason some1 else can do the same ...how do i change the code so that only 1 person can use a specific username ?
6 Answers
+ 2
check if it exists
+ 1
Then you should alert that username is taken.
Count your rows for that username before you insert a new one.
function exists($username) {
$q = $db->prepare(âselect id from users where username=:uâ);
$q->bindParam(â:uâ, $username);
$q->execute();
return $q->rowCount() > 0;
}
+ 1
Solution 1:
Why not add secret password
(If you're using server side language )
Solution 2:
you can make the username name secret for example
If i entered
23cfxkao196529
So Im admin then make script to change my input to my real username
0
It does exist via data base but for example if u try n register as admin it will allow u 2 , i dont want it to
0
Il post my code here then have a look at it then tell me điv been struggling 5hrs with it
0
<?php
$username = filter_input(INPUT_POST, 'username');
$password = filter_input (INPUT_POST, 'password');
If (!empty ($password) && !empty ($username)) {
$host = "localhost";
$dbusername = "root";
$dbpassword = " ";
$dbname = "test";
//create connection
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);
If (mysqli_connection_error() ) {
die('connection error ( '.mysqli_connect_errno ().')');
}else {
$sql = "INSERT INTO account (username, password) VALUES ('$username' , '$password') ";
If ($conn->query($sql) ){
Echo "SUCCESFULLY REGISTERED";
}else {
Echo "Registration failed: error (". $conn->error.") ";
}
}
}
?>