|
-
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>
-
Apr 27th, 2007, 01:17 AM
#2
Re: proble with session
you're missing a bracket. this fixes it:
PHP Code:
$query= "insert into user (username, password) " . "values ( '" . $_POST['username'] . "', " .
"password('" . $_post['password'] . "'));";
if you would simply call mysql_error() within your die()'s, you could quickly try to defuse problems like these yourself.
-
Apr 30th, 2007, 03:11 AM
#3
Re: proble with session
 Originally Posted by omarali
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>
mysql_escape_string() is your friend
-
Apr 30th, 2007, 06:19 PM
#4
Thread Starter
Member
proble with login
Hi
please help this code doesn't work and keep saying query not exquted and i can't see problem with the query command.
PHP Code:
<?php // script to check if the user stored in the MySQL database previously
session_start();
include "conn.inc.php";
if(isset($_POST['submit']))
{
$query = "select username, password from user " . "where username = '" . $_POST['username'] ."'" . "ADN password = (PASSWORD('" . $_POST['password'] . " '))";
// excute the query
$result = mysql_query($query)
or die("query not excuted");
if(mysql_num_rows($result) == 1)
{
$_SESSION['user_logged'] = $_SESSION['username'];
$_SESSION['user_password'] = $_SESSION['password'];
header("Refresh: 5; URL=" . $_POST['redirect'] . "");
echo " you being redirected to your original page reques<br>";
echo "(if your browser not support this, " .
"<a href =\"" . $_POST['redirect'] . "\"> Click here</a>)";
}
else
{
?>
<html>
<head><title> user_login</title></head>
<body>
<p>
invalid and /or password<br>
Not registered?
<a href="register.php">Click here</a> to register.<br>
<form action="user_login.php" method="POST">
<input type="hidden" name="redirect" value="<?php echo $_POST ['redirect']; ?>">
Username : <input type="text" name="username"><br>
Password : <input type="password" name="password"><br><br>
<input type="submit" name="submit" value="Login">
</form>
</p>
</body>
</html>
<?php
}
}
else
{
if(isset($_GET['redirect']))
{
$redirect = $_GET['redirect'];
}else
{
$redirect ="index1.php";
}
?>
<html>
<head><title>Management system </title></head>
<body>
<p>
login below by supplying your username/password..<br>
or<a href="register.php"> Click here</a> to register.<br><br>
<form action="user_login.php" method="POST">
<input type="hidden" name="redirect" value="<?php echo $redirect; ?>">
Username : <input type="text" name="username"><br>
Password : <input type="password" name="password"><br><br>
<input type="submit" name="submit" value="Login">
</form>
</p>
</body>
</html>
<?php
}
?>
-
Apr 30th, 2007, 07:45 PM
#5
Re: proble with login
are you getting a mysql error?
My usual boring signature: Something
-
May 1st, 2007, 01:19 AM
#6
Thread Starter
Member
proble with login
Hi
I get query not excute but when I execute the code bellow, I get this error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''uuu)' at line 1"
PHP Code:
<?php // script to process the registration
// initialize variable and register broweser
session_start();
ob_start();
// file contain connection to the database
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 users " . "where username = '" . $_POST['username'] . "';";
//mysql_query($sql) or die(mysql_error());
#excute the query
$result = mysql_query($query)
or die(mysql_error());
if (mysql_num_rows($result) != 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
$result = mysql_query($query)
or die(mysql_error());
$_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"> <b>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
<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>
-
May 1st, 2007, 09:24 AM
#7
Re: Problem with session and login
-
May 1st, 2007, 12:02 PM
#8
Re: Problem with session and login
you're STILL missing the bracket I told you about in the first post that I made.. that's the only problem in your script.
-
May 2nd, 2007, 08:00 PM
#9
New Member
Re: Problem with session and login
Hi I did fixed the bracket but now when typing to the form withcorrect user and password keep said invalid username and password
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
|