Skip to content

Instantly share code, notes, and snippets.

@Reevan799
Created March 8, 2020 05:16
Show Gist options
  • Select an option

  • Save Reevan799/1a3a984214a4879b0ffa527c70f3d84a to your computer and use it in GitHub Desktop.

Select an option

Save Reevan799/1a3a984214a4879b0ffa527c70f3d84a to your computer and use it in GitHub Desktop.
Fixed Sql Injection Problem
<form id="register" class="input_group" action="registration.php" method="post" required>
<input type="username" class="input_field" placeholder="Username" name="username" required>
<input type="email" class="input_field" placeholder="Email Id" name="email" required>
<input type="password" class="input_field" placeholder="Password" name="password" required>
<input type="checkbox" class="checkbox" name="checkbox"> <span>I agree to the term & conditions</span>
<button type="submit" class="submit_btn">Register</button>
</form>
<?php
session_start();
$conn = mysqli_connect('localhost','root','7777','gm-registration');
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$s = "select * from users where username = '$username'";
$result = mysqli_query($conn, $s);
$num = mysqli_num_rows($result);
if($num==1){
echo "This Username is Already Taken";
}
else{
$stmt = $conn->prepare("INSERT INTO users(username, email, password) VALUES(?,?,?)");
$stmt->bind_param("sss", $username, $email, $password);
$stmt->execute();
echo "Registration Successful";
$stmt->close();
$conn->close();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment