Author Topic: Problems with the login form  (Read 124 times)

androsS

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Problems with the login form
« on: January 26, 2012, 01:07:00 PM »
Hello!!

My problem is this one. I have two php files. One with the insert data(register) an another with the select data(Login).

the insert data is working, but  in the login, is not working the validation. I put values that are not stored in the database and I can enter in a third page, something that I dont want. 

 Can anyone tell whats wrong.

thanks

The login
PHP Code: [Select]


<?php
require_once 'Register.php';
require_once 
'VAdministration.php';
?>


<?php
if (isset($_POST["enter"])) {
//set up names of database and table to use
$db_name "projectov5";
$table_name "users";
$host="localhost"// Host name
$username="root"// Mysql username
$password="....."// Mysql password
$name =$_POST['name'];
$pass =  $_POST['password'];
//connect to server and select database
mysql_connect("$host""$username""$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

//build and issue the query
$sql "SELECT name, password FROM users WHERE name = '$name' AND password = '$pass'";
$result=mysql_query($sql);
//print a message or redirect elsewhere, based on result
if ($result) {
header'Location: nextPage.php');
} else {
echo 
"<p style='color:green;'>Sorry no user register.</p>";
}
mysql_close();

}
?>


The register form

PHP Code: [Select]

<?php require_once 'conectorBD.php'?>
<?php 
require_once 'funcionesU.php';?>

<?php 
if (isset($_POST["enter"])) {

$name $_POST['name'];
$password$_POST['password'];


$result saveUser($dbc,$nombre,$password);

if( 
$result ){
	
echo 
"<p style='color:green;'>The user was stored.</p>";
} else {
	
echo 
"<p style='color:red;'>Error....</p>";
}

mysql_close();
}

?>
   

this is the connector of DB of register.php
PHP Code: [Select]

<?php
define 
('DB_USER''root');
define ('DB_PASSWORD''....');
define ('DB_HOST''localhost');
define ('DB_NAME''projectov5');

$dbc = @mysql_connect (DB_HOSTDB_USERDB_PASSWORDDB_NAME) OR die ('Error: ' mysqli_connect_error() );

?>



the funcionesU of registerPage
PHP Code: [Select]

<?php


function saveUser($dbc,$name,$password) {
	
mysql_select_db("projectov5"$dbc);

	
$query "INSERT INTO users(name, password) VALUES('$name','$password')";
	
//
	
$result mysql_query($query);

	
echo 
mysql_error();

	
return 
$result;
}
?>


thanks

androsS

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Problems with the login form Part 2
« Reply #1 on: January 26, 2012, 03:04:52 PM »
I change one line in the login code but still not working...

anyone have the answer for my problem
thanks
PHP Code: [Select]


<?php
if (isset($_POST["enter"])) {
//set up names of database and table to use
$db_name "projectov5";
$table_name "users";
$host="localhost"// Host name
$username="root"// Mysql username
$password="....."// Mysql password
$name =$_POST['name'];
$pass =  $_POST['password'];
//connect to server and select database
mysql_connect("$host""$username""$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

//build and issue the query
$sql "SELECT name, password FROM users WHERE name = '$name' AND password = '$pass'";
$result=mysql_query($sql);
//print a message or redirect elsewhere, based on result
if (mysql_fetch_array($result)){
header'Location: Principal.php');
} else {
echo 
"<p style='color:green;'>User not in the database.</p>";
}
mysql_close();

}
?>