Create Row In Database Function

PHOTO EMBED

Sun Apr 02 2023 18:56:09 GMT+0000 (Coordinated Universal Time)

Saved by @Joe_Devs #php #mysql

function create(){
	//If linking to database from external file
    global $connection;

	//Grab form data
    $username = $_POST['username'];
    $password = $_POST['password'];
	
    //Sanatize user input
    $username = mysqli_real_escape_string($connection,$username);
    $password = mysqli_real_escape_string($connection,$password);

	//Query that inserts value into database
    $query = "INSERT INTO users(username,password) ";
    $query .= "VALUES ('$username', '$password')";

    $result = mysqli_query($connection,$query);

    if(!$result){
        die('Query failed' . mysqli_error());
    }
}


//HTML FILE
if (isset($_POST['submit'])) {
    create();

}
content_copyCOPY