In my app, this PHP code should check for existing usernames and if one exists, don't create a new row in the database. No matter what, the app still creates new rows in the MySQL database.
Here is the code for checking:
<?php
//$password = "password";
//$username = "username";
require "conn.php";
$password = $_POST["password"];
$username = $_POST["username"];
//$url_id = mysql_real_escape_string($_GET['username']);
$sql = "SELECT * FROM UserData WHERE username ='$username'";
$result = mysql_query($sql);
if(mysql_num_rows($result) >0){
break;
}else{
$stmt = $conn->prepare("INSERT INTO UserData (username,password) VALUES (:username,:password)");
$params = array(
':username' => $username,
':password' => $password
);
$stmt->execute($params);
}
?>