I want to have an online account database in my app and I’ve got the database working and I can post values to the database. The problem is that multiple users can have the same username and password. Multiple account with the same password is just fine but not usernames!
The way everything is connected in my app right now is that I use XAMPP (just for the testing, will change later ofc), in my xampp folder I have a .php file and a .sqlite file. My app then uses POST to send the user chosen username and password, to the php file. The php file then posts the new value to the database file.
So far I’ve come up with this code (in the php file):
//open the database
$db = new PDO('sqlite:accountDB.sqlite');
//create the table
$db-\>exec("CREATE TABLE Accounts (Id INTEGER PRIMARY KEY, Username TEXT, Password TEXT)");
$username = $\_POST['username'];
$password = $\_POST['password'];
if ($username != "" and $password != ""){
//insert some data...
$myCount = $db-\>exec("SELECT COUNT(Username) AS NUMBER FROM Accounts WHERE Username == '$username';");
if ($myCount == 0){
$db-\>exec("INSERT INTO Accounts (Username, Password) VALUES ('$username', '$password');");
}
}
But it isn’t working!
Help please!
Oskwish [import]uid: 24111 topic_id: 21088 reply_id: 321088[/import]
