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 ?

7th Dec 2018, 1:57 PM
Darren Chibi
6 Answers
+ 2
check if it exists
7th Dec 2018, 2:01 PM
Toni Isotalo
Toni Isotalo - avatar
+ 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; }
7th Dec 2018, 2:12 PM
Toni Isotalo
Toni Isotalo - avatar
+ 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
7th Dec 2018, 2:17 PM
Ahlin Chan
Ahlin Chan - avatar
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
7th Dec 2018, 2:05 PM
Darren Chibi
0
Il post my code here then have a look at it then tell me 😂iv been struggling 5hrs with it
7th Dec 2018, 2:27 PM
Darren Chibi
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.") "; } } } ?>
7th Dec 2018, 2:45 PM
Darren Chibi