can any one help
Moderator: General Moderators
can any one help
can any one help me when i try out this code it shows if (!empty($_POST['username'])) in the login box how do i make it not show if (!empty($_POST['username']))
<?php
session_start();
// Check if he wants to login:
if (!empty($_POST['username']))
{
require_once("connect.php");
// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
WHERE username = '$_POST[username]'
AND password = '$_POST[password]'")
or die ("Error - Couldn't login user.");
$row = mysql_fetch_array($query)
or die ("Error - Couldn't login user.");
if (!empty($row['username'])) // he got it.
{
$_SESSION['username'] = $row['username'];
echo "Welcome $_POST[username]! You've been successfully logged in.";
exit();
}
else // bad info.
{
echo "Error - Couldn't login user.<br /><br />
Please try again.";
exit();
}
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="login.php" method="post">
<table width="75%" border="1" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="100%"><h5>Login</h5></td>
</tr>
<tr>
<td width="100%"><label>Username: <input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>"></label></td>
</tr>
<tr>
<td width="100%"><label>Password: <input type="password" name="password" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><input type="submit" value="Login!"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
session_start();
// Check if he wants to login:
if (!empty($_POST['username']))
{
require_once("connect.php");
// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
WHERE username = '$_POST[username]'
AND password = '$_POST[password]'")
or die ("Error - Couldn't login user.");
$row = mysql_fetch_array($query)
or die ("Error - Couldn't login user.");
if (!empty($row['username'])) // he got it.
{
$_SESSION['username'] = $row['username'];
echo "Welcome $_POST[username]! You've been successfully logged in.";
exit();
}
else // bad info.
{
echo "Error - Couldn't login user.<br /><br />
Please try again.";
exit();
}
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="login.php" method="post">
<table width="75%" border="1" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="100%"><h5>Login</h5></td>
</tr>
<tr>
<td width="100%"><label>Username: <input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>"></label></td>
</tr>
<tr>
<td width="100%"><label>Password: <input type="password" name="password" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><input type="submit" value="Login!"></td>
</tr>
</table>
</form>
</body>
</html>
Re: can any one help
Use isset(trim($_POST['username'])) instead of if (!empty($_POST['username']))
Re: can any one help
Do you mean it shows this in the username textbox?5475427 wrote:it shows if (!empty($_POST['username'])) in the login box
Code: Select all
<? echo $_POST[username]; ?>Also, read about SQL Injection and always use quotes around a string literal array index.
isset() and trim() cannot be nested.pbs wrote:Use isset(trim($_POST['username']))
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Thu Jun 17, 2010 4:21 pm, edited 1 time in total.
Re: can any one help
when i change it to isset(trim($_POST['username'])) it says Fatal error: Can't use function return value in write context in C:\wamp\www\new\register.php on line 4
here is the code agan
<?php
session_start();
// Check if he wants to login:
isset(trim($_POST['username']))
{
require_once("connect.php");
// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
WHERE username = '$_POST[username]'
AND password = '$_POST[password]'")
or die ("Error - Couldn't login user.");
$row = mysql_fetch_array($query)
or die ("Error - Couldn't login user.");
if (!empty($row['username'])) // he got it.
{
$_SESSION['username'] = $row['username'];
echo "Welcome $_POST[username]! You've been successfully logged in.";
exit();
}
else // bad info.
{
echo "Error - Couldn't login user.<br /><br />
Please try again.";
exit();
}
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="login.php" method="post">
<table width="75%" border="1" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="100%"><h5>Login</h5></td>
</tr>
<tr>
<td width="100%"><label>Username: <input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>"></label></td>
</tr>
<tr>
<td width="100%"><label>Password: <input type="password" name="password" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><input type="submit" value="Login!"></td>
</tr>
</table>
</form>
</body>
</html>
here is the code agan
<?php
session_start();
// Check if he wants to login:
isset(trim($_POST['username']))
{
require_once("connect.php");
// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
WHERE username = '$_POST[username]'
AND password = '$_POST[password]'")
or die ("Error - Couldn't login user.");
$row = mysql_fetch_array($query)
or die ("Error - Couldn't login user.");
if (!empty($row['username'])) // he got it.
{
$_SESSION['username'] = $row['username'];
echo "Welcome $_POST[username]! You've been successfully logged in.";
exit();
}
else // bad info.
{
echo "Error - Couldn't login user.<br /><br />
Please try again.";
exit();
}
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="login.php" method="post">
<table width="75%" border="1" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="100%"><h5>Login</h5></td>
</tr>
<tr>
<td width="100%"><label>Username: <input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>"></label></td>
</tr>
<tr>
<td width="100%"><label>Password: <input type="password" name="password" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><input type="submit" value="Login!"></td>
</tr>
</table>
</form>
</body>
</html>
- SimpleManWeb
- Forum Commoner
- Posts: 57
- Joined: Wed Dec 30, 2009 4:15 pm
- Location: New Hampshire, USA
Re: can any one help
You forgot the "If" in your isset statement, try this code:
Hope this helps
Code: Select all
<?php
session_start();
// Check if he wants to login:
if (isset(trim($_POST['username']))) {
require_once("connect.php");
// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
WHERE username = '$_POST[username]'
AND password = '$_POST[password]'")
or die ("Error - Couldn't login user.");
$row = mysql_fetch_array($query)
} else {
die ("Error - Couldn't login user.");
}
?>
Re: can any one help
i still get the same error 
Fatal error: Can't use function return value in write context in C:\wamp\www\new\login.php on line 4
when i change it to
<?php
session_start();
// Check if he wants to login:
if (isset(trim($_POST['username']))) {
require_once("connect.php");
// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
WHERE username = '$_POST[username]'
AND password = '$_POST[password]'")
or die ("Error - Couldn't login user.");
$row = mysql_fetch_array($query)
} else {
die ("Error - Couldn't login user.");
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="login.php" method="post">
<table width="75%" border="1" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="100%"><h5>Login</h5></td>
</tr>
<tr>
<td width="100%"><label>Username: <input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>"></label></td>
</tr>
<tr>
<td width="100%"><label>Password: <input type="password" name="password" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><input type="submit" value="Login!"></td>
</tr>
</table>
</form>
</body>
</html>
Fatal error: Can't use function return value in write context in C:\wamp\www\new\login.php on line 4
when i change it to
<?php
session_start();
// Check if he wants to login:
if (isset(trim($_POST['username']))) {
require_once("connect.php");
// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
WHERE username = '$_POST[username]'
AND password = '$_POST[password]'")
or die ("Error - Couldn't login user.");
$row = mysql_fetch_array($query)
} else {
die ("Error - Couldn't login user.");
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="login.php" method="post">
<table width="75%" border="1" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="100%"><h5>Login</h5></td>
</tr>
<tr>
<td width="100%"><label>Username: <input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>"></label></td>
</tr>
<tr>
<td width="100%"><label>Password: <input type="password" name="password" size="25" value=""></label></td>
</tr>
<tr>
<td width="100%"><input type="submit" value="Login!"></td>
</tr>
</table>
</form>
</body>
</html>
- SimpleManWeb
- Forum Commoner
- Posts: 57
- Joined: Wed Dec 30, 2009 4:15 pm
- Location: New Hampshire, USA
Re: can any one help
Oh man, I should have looked at the code more closely. You can use functions like trim when you are doing things like isset.
Use this instead:
Use this instead:
Code: Select all
<?php
session_start();
// Check if he wants to login:
if (isset($_POST['username'])) {
require_once("connect.php");
// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
WHERE username = '".trim($_POST[username])."'
AND password = '".trim($_POST[password])."'")
or die ("Error - Couldn't login user.");
//$row = mysql_fetch_array($query)
} else {
die ("Error - Couldn't login user.");
}
?>
Re: can any one help
5475427 wrote:when i change it to isset(trim($_POST['username'])) it says Fatal error
Did you overlook my post? I said that nesting isset() and trim() is wrong. I also suggested that you should not use short open tags.5475427 wrote:i still get the same error
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Thu Jun 17, 2010 4:22 pm, edited 1 time in total.
Re: can any one help
- SimpleManWeb
- Forum Commoner
- Posts: 57
- Joined: Wed Dec 30, 2009 4:15 pm
- Location: New Hampshire, USA
Re: can any one help
That's good news, that means it worked. I put that code in there as a test and forgot to take it out. Last try. This one will work for sure:
Code: Select all
<?php
session_start();
// Check if he wants to login:
if (isset($_POST['username'])) {
require_once("connect.php");
// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
WHERE username = '".trim($_POST[username])."'
AND password = '".trim($_POST[password])."'")
or die ("Error - Couldn't login user.");
//$row = mysql_fetch_array($query)
}
?>
Re: can any one help
now it shows <? echo $_POST[username]; ?> in the login box and when u click login nothen happens like i put my user and pass and nothen hapend
Re: can any one help
Knock, knock.
Reread this topic.
Edit: This post was recovered from search engine cache.
Reread this topic.
Edit: This post was recovered from search engine cache.