prasa_vj Posted July 13, 2017 Share Posted July 13, 2017 (edited) <?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 Edited July 13, 2017 by cyberRobot added [code][/code] tags; merged posts Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted July 13, 2017 Share Posted July 13, 2017 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: http://php.net/manual/en/mysqli-result.fetch-array.php Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted July 13, 2017 Share Posted July 13, 2017 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.