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]
<?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 "
Sorry no user register.
";
}
mysql_close();
}
?>
[/php]
The register form
[php]
<?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 "
The user was stored.
";
} else {
echo "
Error....
";
}
mysql_close();
}
?>
[/php]
this is the connector of DB of register.php
[php]
<?php
define ('DB_USER', 'root');
define ('DB_PASSWORD', '....');
define ('DB_HOST', 'localhost');
define ('DB_NAME', 'projectov5');
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Error: ' . mysqli_connect_error() );
?>
[/php]
the funcionesU of registerPage
[php]
<?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;
}
?>
[/php]
thanks