php MySQL

Hi guys,
I’ve got problem with my new website. If I try login inside, the web answer me:

Array ( [0] => You need to enter a username and password )

The web show me only this error
Xampp is turn on, In phpadmin I got configuration:

  • Web
    • Users

this is code:

//connect.php

[php]<?php

$connect_error = ‘Error message, please wait we are back for seconds’;
$con = mysqli_connect(‘localhost’,‘root’,’’);
mysqli_select_db($con,‘test’) or die($connect_error);
?>[/php]

// init.php

[php]

<?php session_start(); error_reporting(0); require 'database/connect.php'; require 'functions/users.php'; require 'functions/general.php'; $errors = array(); ?>

[/php]

// users.php

[php]

<?php function user_exists($username) { $username = sanitize($username); return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"),0) == 1)? true : false; } function user_active($username) { $username = sanitize($username); return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND 'active' = 1"), 0) == 1) ? true : false; } ?>

[/php]

// users.php
[php]

<?php include 'core/init.php'; if (empty ($_POST) === false) { $username = $_POST ['username']; $password = $_POST ['password']; if (empty ($username) === true || empty ($password) === true) { $errors [] = 'You need to enter a username and password'; } else if (user_exists($username) === false) { $errors [] = 'We can\'t find that usernam'; } else if (user_active($username) === false ) { $errors [] = 'You haven\'t accouount'; } else { // here } print_r($errors); } ?>

[/php]

// general.php

[php]<?php

function sanitize ($data) {

return mysql_real_escape_string($data);

}

?>[/php]

Please help me… what I do wrong ?

This should be the page a form submits to. The error says you didn’t supply a username or password. From what you show, you didn’t.

Thanks for reply ! but I must ask you something becouse, this this command doesn’t works:

[php]else if (user_exists($username) === false) {
$errors [] = ‘We can’t find that usernam’;

} else if (user_active($username) === false ) {
	$errors [] = 'You haven\'t accouount';
	
	
}[/php]

and this is problem with bad configuration in phpmyadmin or in my code ?

Well, as Astonecipher said, you did not show your form code. But, also looking at your error and your
code, it looks like the issue is this line:

if (empty ($username) === true || empty ($password) === true) {

So either you are not reading the posted values or one of these are true.
This means that the $username or $password variables are empty.

Check your spelling on your FORM where your fields are for these to. You may have spelled it differently.

I find problem … :smiley: thanks for help !

[php]
LOGIN

   <form action="login.php" method="post">
	
	<ul id="login">
	
	USERNAME: 
	<input type="text" name="username">

			
	PASSWORD: 
			<input type="password" name="password">
			
			
					
	<input type="submit" value="log in">
					
				
				
   
   </ul>
 </form>  
[/php]

in here i had name=“username”>

Sponsor our Newsletter | Privacy Policy | Terms of Service