|
-
Apr 26th, 2007, 08:58 PM
#1
Thread Starter
Member
Problem with session and login
Hi mate
Thank you for the reply , sorry another hassle so please tell me what is wrong with this code, it suppose user login or register if they are not a member, when run it gave query not executed, I did check the table field are the same with the query and the database connected. Thank you very much
to be noted the database connection inside the extenral file "conn.inc.php"
PHP Code:
<?php // script to process the registration
// initialize variable and register broweser
session_start();
ob_start();
include "conn.inc.php";
?>
<html>
<head><title>Management System</title></head>
<body>
<?php
// check for if the user already exist and make sure the field not empty.
if(isset($_POST['submit']) && $_POST['submit'] == "Register")
{
if ($_POST['username'] != "" && $_POST['password'] != "")
{
//create SQL query
$query = "select username from user " . "where username = '" . $_POST['username'] . "'; ";
#excute the query
$rs = mysql_query($query)
or die(mysql_error());
if (mysql_num_rows($rs) != 0)
{
?>
<p>
<font color="Red"> <b>The Username,
<?php
echo $_POST['username']; ?>, is already in use Please choose another
</b></font>
<form action="register.php" method="POST">
Username : <input type="text" name="username"> <br>
Password : <input type= "password" name="password" value="<?php echo $_POST['password']; ?>"><br>
<input type="submit" name="submit" value="Register">
<input type="reset" value="Clear">
</form>
</p>
<?php
}
else
{
//create SQL query
$query= "insert into user (username, password) " . "values ( '" . $_POST['username'] . "', " .
"password('" . $_post['password'] . "');";
// Excute query
$rs = mysql_query($query)
or die("Query could not excuted");
$_SESSION['user_logged'] = $_POST['username'];
$_SESSION['user_password'] = $_POST['password'];
?>
<P>
Thank you, <?php echo $_POST['username']; ?> for Registering <br>
<?php
header("Refresh: 5; URL=index1.php");
echo "Your regiseration is complete" .
"You are being sent to the request page<br>";
echo "(if your browser doesn't support this, " .
"<a href=\"index1.php\"> Click here</a>)";
die();
}
}else
{
?>
<P>
<font color = "red"> The Username and password required</b></font>
<form action="register.php" method="POST">
Username : <input type="text" name="username" value="<?php echo $_POST['username']; ?>"><br>
Password : <input type="password" name="password" value=""<?php echo $_POST['password']; ?>"><br>
<input type="submit" name="submit" value="Register">
<input type="reset" value="Clear">
</form>
</P>
<?php
}
}else
{
?>
<p>
Welcome to Registeration<br>
Username and password required
<font color = "red"> username and password required</b></font>
<form action="register.php" method="POST">
Username : <input type="text" name="username"><br>
Password : <input type="password" name="password"><br>
<input type="submit" name="submit" value="Register">
<input type="reset" value="Clear">
</form>
</p>
<?php
}
?>
</body>
</html>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|