Jump to content

i am new to php right now i am learning on mysqli and sesion so please help in following template


prasa_vj

Recommended Posts

<?php  //Start the Session
session_start();
include('connect.php');
 
if (isset($_POST['login'])){
//3.1.1 Assigning posted values to variables.
 
    //3.1.2 Checking the values are existing in the database or not
    $result = mysqli_query($conn,"SELECT email,password FROM task1 WHERE email='$_POST[email]' and password='$_POST[password]'");
    $count = mysqli_fetch_array($result);
    if ($count==1) {
        $_SESSION["myid"] =$count['id'];
        header('Location:testview.php');
 
    }else{
        //3.1.3 If the login credentials doesn't match, he will be shown with an error message.
        echo "Invalid Login Credentials.";
    }
}
?>
 

error

 

Warning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\prasad\Test\conn-login.php on line 10

 

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\prasad\Test\conn-login.php on line 12

Invalid Login Credentials.

this is what i am getting ..valuable suggestion please

Link to comment
Share on other sites

Have you looked into displaying MySQL errors? More information can be found here:

http://php.net/manual/en/mysqli-driver.report-mode.php

 

Also note that your query is susceptible to SQL injection attacks. At some point, if you haven't already, you'll want to look into prepared statements.

 

Lastly, you should double check what the mysqli_fetch_array() function returns:  :happy-04:

http://php.net/manual/en/mysqli-result.fetch-array.php

Link to comment
Share on other sites

Side note: if you don't need the numeric array that's returned, in addition to the associative array, by the mysqli_fetch_array() function, you could use mysqli_fetch_assoc() instead. More information can be found here:

http://php.net/manual/en/mysqli-result.fetch-assoc.php

 

Based on the following quote from the manual, mysqli_fetch_array() may not return the associative array in some cases. I imagine it depends on the server setup...

 

Fetch a result row as an associative, a numeric array, or both

 

If that's the case, mysqli_fetch_assoc() is going to be the safer choice.  :happy-04:

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.