-2

I have been trying to fix this issue I'm having but I am not able to figure out how. This is my current code:

if (isset($_POST['username'])){

    $username = stripslashes($_POST['username']);

    $username = mysqli_real_escape_string($con,$username); 
    $email = stripslashes($_POST['email']);
    $email = mysqli_real_escape_string($con,$email);
    $password = stripslashes($_POST['password']);
    $password = mysqli_real_escape_string($con, $password);

    $password = md5($password);

    $geboorte_datum = $_POST['geboorte_datum'];
    $naam = $_POST['naam'];
    $adres = $_POST['adres'];
    $postcode = $_POST['postcode'];
    $woonplaats = $_POST['woonplaats'];

    $query = "
        INSERT INTO 
            `users` (id, username, password, email, geboortedatum, medewerker, volledige_naam, volledige_adres, postcode, woonplaats)
        VALUES 
            (NULL, '$username', '$password', '$email', '$geboorte_datum', '0', '$naam', '$adres', '$postcode', '$woonplaats')
    ";

    $result = mysqli_query($con,$query);
    if($result){
        echo "
            <div class='form'>
                <h3>Je bent succesvol geregistreerd</h3>
                <br/>Klik hier om <a href='inloggen.php'>in te loggen</a>
            </div>
        ";
    } else {
        echo "
            <div class='form'>
                <h3>Fout opgetreden</h3>
                <br/>Klik hier om <a href='registreren.php'>opnieuw te proberen</a>
            </div>
        ";
    }
}else{
?>

This unfortunately gives me 4 errors that are all the same:

mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in....

Would any of you guys be able to figure this out? Much appreciated!

Dharman
  • 30,962
  • 25
  • 85
  • 135
Tom Kik
  • 1
  • 2
  • 5
    Please do not use `md5` for your password. use php's `password_hash` and `password_verify`. Also use prepared statements – Rotimi May 30 '17 at 08:27
  • Do you include your database connection? Seems `$con` is undefined and does not contain database connection. I'm guessing you have a database connection file? You should include it here – Rotimi May 30 '17 at 08:28
  • Your connection is borked (hence `null`) - I'm guessing this is a duplicate of https://stackoverflow.com/questions/2973202/mysqli-fetch-array-mysqli-fetch-assoc-mysqli-fetch-row-expects-parameter-1 – CD001 May 30 '17 at 08:28
  • A quick way to debug is to check the output of `$con` – Chris Burton May 30 '17 at 08:29

1 Answers1

-2

first check the $con

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$username = mysqli_real_escape_string($con, $username);
echo $username;
karthickeyan
  • 372
  • 2
  • 12