Dalton Napala Dalton Napala - 8 days ago 6
MySQL Question

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null

Can somebody help me understand what it means because When I look at my code and compare it to the person that learning from I seem to not have any problem of having any mistake and I even tried to copy his code and I still get the


Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli,
null given in /home/daltonnapala/public_html/mysql/Grab.php on line 15

Warning: mysqli_query() expects parameter 1 to be mysqli, null given
in /home/daltonnapala/public_html/mysql/Grab.php on line 17

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result,
null given in /home/daltonnapala/public_html/mysql/Grab.php on line 19


Now I kinda do understand that having this expects parameter 1 to be mysqli, null given that it does not have the variables or something since I read some of the question and answers, but I still don't fully understand and why im having these warning or errors.

Here is my code for the Sign up page:

<?php

if (array_key_exists('email', $_POST) OR array_key_exists('password', $_POST)){

if ($_POST['email'] == ''){

echo "<p>Please put in your email!</p>";

} else if ($_POST['password'] == ''){

echo "<p>Please put in your Password!</p>";

} else {

$query = "SELECT `id` FROM `users` WHERE email ='".mysqli_real_escape_string($link, $_POST['email'])."'";

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

if(mysqli_num_rows($result) > 0){

echo "<p>That email address has already been sign in</p>";

}

}

}

$link = mysqli_connect("localhost", "examplebb", "kle]cwdum)#]", "examplebb");
if (mysqli_connect_error()) {

die("Could not connect to database");

}

?>

<form method="post">

<input name="email" type="text" placeholder="Email">

<input name="password" type="password" placeholder="Password here">

<input type="submit" value="Sign up!">

</form>

Answer

Seems to me that you are defining $link after executing mysqli commands. You first have to define $link before you may execute mysqli commands. Therefore, try to put the following lines at the top of your file right after the php tag and see if that helps:

$link = mysqli_connect("localhost", "examplebb", "kle]cwdum)#]", "examplebb");
if (mysqli_connect_error()) {

die("Could not connect to database");
Comments