Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
PHP
<?php 
    require_once'connection/dbcon.php'; 
    	if (isset($_POST['login']))
    		{
    			$username = mysqli_real_escape_string($db, $_POST['user']);
    			$password = mysqli_real_escape_string($db, $_POST['pass']);
                
                $query 		= mysqli_query($db, "SELECT * FROM users WHERE  password='".$password."' and username='".$username."'");
    			$row		= mysqli_fetch_assoc($query);
    			$num_row 	= mysqli_num_rows($query);
                // var_dump($row);
                // var_dump($num_row);
                // exit;
    			if ($num_row > 0) 
    				{			
    					$_SESSION['user_id']=$row['sn'];
    					header('location:home.php');
     
    				}
    			else
    				{
    					echo 'Invalid Username and Password Combination';
    				}
    		}
>


What I have tried:

i just tried to solve this problem but still dont get the solution.
Posted
Updated 26-Apr-17 20:37pm
v3
Comments

It looks like your issue is here probably

PHP
$username = mysqli_real_escape_string($db, $_POST['user']);


Your error message doesn't match up with the code you posted but it is pretty clear. Your POST to login.php does not contain a "user" field. Check what you are posting to make sure "user" is one of the form vars being passed to login.php.

You can use a tool like fiddler, chrome dev tools, or firebug/firefox dev tools to see what is being posted.
 
Share this answer
 
Never build an SQL query by concatenating with user inputs, it is named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability.
SQL injection - Wikipedia[^]
SQL Injection[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900