...

View Full Version : php problem



fergie223
08-22-2006, 09:06 PM
alright this is my login system(it is working ok) here but the problem i am having is that i want to add user_id and user_password to my database from my webpage and these user_id and user_passwords would be used to login to the system


login.php




session_start();

$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
include 'config.php';
include 'opendb.php';

$userId = $_POST['txtUserId'];
$password = $_POST['txtPassword'];

// check if the user id and password combination exist in database
$sql = "SELECT user_id
FROM tbl_auth_user
WHERE user_id = '$userId' AND user_password =MD5('$password')";

$result = mysql_query($sql) or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) == 1) {
// the user id and password match,
// set the session
$_SESSION['db_is_logged_in'] = true;

// after login we move to the main page
header('Location:);
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}


}
?>
<html>
<head>
<title>Basic Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
if ($errorMessage != '') {
?>



ive tried this with no suucess

insertdata.html



<html>
<head>
<title>Admin section</title>
</head>
<body>



<h1>Add a student </h1>
<form method="post" action="">
<p> please enter your student password and e-mail address below.</p>
<p>
Please enter student email address:
<br>
<input type="text" name="user_id" size="35">
<br>
Please enter student password:
<br>
<input type="text" name="user_password" size="35">

<br>
</p>
<input type="submit" value="Add address">
<input type="reset" value="start over">
</form>

<br>
<HR>
<br>


insertdata.php


<html>
<head>
<title>Return Page</title>
</head>
<body>
<h1>Thank you for filling out my form!</h1>
<?php
$link_id = mysql_connect('', '', '') or die ("Could not connect: " . mysql_error());



mysql_select_db("", $link_id);


$user_id = addslashes($user_id); // addslashes() escapes any characters that
// could confuse MySQL, i.e. ',`,", etc.
$user_password = addslashes($user_password);


$insert_sql = "INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('$user_id', '$user_password')";
mysql_query($insert_sql, $link_id) or die ("Insert failed: " . mysql_error());
mysql_close($link_id);
?>

<p>Thank you, <?php echo $user_id ?>, was added to the database!</p>


database



CREATE TABLE tbl_auth_user (
user_id VARCHAR(10) NOT NULL,
user_password CHAR(32) NOT NULL,
PRIMARY KEY (user_id)
);

INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('theadmin', MD5('chumbawamba'));
INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('webmaster', MD5('webmistress'));



ANY HELP WOULD BE MUCH APPRECIATED THANK YOU IN ADVANCE:thumbsup:

FoxyForest
08-22-2006, 09:19 PM
What is the exact problem that you are having? What is the error? What is not working correctly?

Spookster
08-23-2006, 05:35 AM
In the future, please use a more descriptive subject when posting a question. See posting guidelines. (http://www.codingforums.com/postguide.htm)

saecula
08-23-2006, 05:44 AM
He wants a register option basically.

fergie223
08-23-2006, 10:17 AM
sorry bout topic description. the problem i am having is that the user_id and user_password are being entered into the database using insertdata.php but when i try to use these in the login system they dont work. i think it may have something to do with MD5. thanks again:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum