Jump to content

Script Error


Drezard

Recommended Posts

This script doesnt seem to work for some reason. I cant understand why.

Heres the error:
[QUOTE]
Parse error: syntax error, unexpected T_BOOLEAN_AND in C:\Program Files\xampp\htdocs\login_form.php on line 24
[/QUOTE]

Here's the code:

[CODE]
<?php
// initialize a session
session_start();
?>
<html>
<head></head>
<body>

<?php
if (!isset($_SESSION['login']) && !isset($_POST['user'])) {
    // if no data, print the form
?>
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
      Username:<input type="text" name='user'><br>
  Password:<input type="text" name='pass'><br>
        <input type="submit" name="submit">
    </form>
<?php
}
else if (!isset($_SESSION['login'])) {
    // if a session does not exist but the form has been submitted
    // check to see if the form has all required values
    // create a new session
    if (empty($_POST['user'])) && {empty($_POST['pass'])) {
  echo "Please insert your username";
  echo "Please insert your password";
        }
    if (empty($_POST['user'])) {
      echo "Please insert your username";
    }
if (empty($_POST['pass'])) {
  echo "Please insert your username";
  }
 
}
?>
</body>
</html>
[/CODE]

Thanks, Daniel
Link to comment
Share on other sites

right here
[quote]    // if a session does not exist but the form has been submitted
    // check to see if the form has all required values
    // create a new session
    if (empty($_POST['user'][b][color=red][size=12pt])[/size][/color][/b]) && [b][color=red][size=12pt]{[/size][/color][/b]empty($_POST['pass'])) {[/quote]

get rid of the two characters marked in red
Link to comment
Share on other sites

You have 3 if statements back to back....

[code]  if (empty($_POST['user'])) && {empty($_POST['pass'])) {
  echo "Please insert your username";
  echo "Please insert your password";
        }
    if (empty($_POST['user'])) {
      echo "Please insert your username";
    }
if (empty($_POST['pass'])) {
  echo "Please insert your username";
  }[/code]

I dont think you can do that.


use
if...
esle if...
esle...
Link to comment
Share on other sites

<?php
// initialize a session
session_start();
?>
<html>
<head></head>
<body>

<?php
if (!isset($_SESSION['login']) && !isset($_POST['user'])) {
    // if no data, print the form
?>
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
      Username:<input type="text" name='user'><br>
  Password:<input type="text" name='pass'><br>
        <input type="submit" name="submit">
    </form>
<?php
}
else if (!isset($_SESSION['login']))
{
    // if a session does not exist but the form has been submitted
    // check to see if the form has all required values
    // create a new session
  if (empty($_POST['user']) && (empty($_POST['pass'])))
{
echo "Please insert your username";
echo "Please insert your password";
}
  if (empty($_POST['user']))
  {
      echo "Please insert your username";
  }
if (empty($_POST['pass']))
  {
  echo "Please insert your username";
}
}
?>
</body>
</html>


Just use this code.. where you are doing mistake is unnecessary paranthesis closing brackets and Open curl braces.at the end of the line 24 i added one closing paranthesis.

cheers :)
Link to comment
Share on other sites

Try this:
[code]<?php
// initialize a session
session_start();
?>
<html>
<head></head>
<body>

<?php
// if no data, print the form
if (!isset($_SESSION['login']) && !isset($_POST['user']))
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  Username:<input type="text" name='user'><br />
  Password:<input type="text" name='pass'><br />
  <input type="submit" name="submit">
</form>
<?php
}
else if (!isset($_SESSION['login']))
{
    // if a session does not exist but the form has been submitted
    // check to see if the form has all required values
    // create a new session
    if (empty($_POST['user']) && empty($_POST['pass']))
    {
    echo "Please insert your username<br />";
        echo "Please insert your password<br />";
    }
    elseif (empty($_POST['user']))
    {
        echo "Please insert your username<br />";
    }
elseif (empty($_POST['pass']))
    {
  echo "Please insert your username<br />";
}
}
?>
</body>
</html>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.