Skip to content

Instantly share code, notes, and snippets.

@GedMullen
Created November 6, 2015 10:12
Show Gist options
  • Save GedMullen/2dd45563a6e13f4be7f6 to your computer and use it in GitHub Desktop.
Save GedMullen/2dd45563a6e13f4be7f6 to your computer and use it in GitHub Desktop.
$username = $_POST["uname"];
$password = $_POST["pword"];
$con = mysqli_connect("localhost", "student", "", "ryan04");
//check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else {
echo "connected <br />";
$sql = "SELECT * FROM users WHERE name='$username'";
$res = mysqli_query($con, $sql);
$numrows = mysqli_num_rows($res);
if ($numrows == 0) {
$sql = "INSERT INTO users VALUES ('$username', '$password')";
mysqli_query($con, $sql);
$form .= "User successfully created.<br />";
$form .= "<a href='login.php'>Click here to go to login</a>";
} else {
$form .= "<p>User already exists, please try another Username.</p>";
$form .= displayForm();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment