Jump to content


Photo

Script Error


  • Please log in to reply
6 replies to this topic

#1 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 14 September 2006 - 08:00 AM

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

Heres the error:

Parse error: syntax error, unexpected T_BOOLEAN_AND in C:\Program Files\xampp\htdocs\login_form.php on line 24


Here's the 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>

Thanks, Daniel

#2 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 14 September 2006 - 08:04 AM

right here

    // 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'])) {


get rid of the two characters marked in red

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#3 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 14 September 2006 - 08:11 AM

I have repaired that problem but it still gives me the same error.

Can u think of anything else?

- Cheers, Daniel

#4 laide234

laide234
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 14 September 2006 - 08:20 AM

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

  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";
	   }

I dont think you can do that.


use
if...
esle if...
esle...

#5 joshi_v

joshi_v
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 14 September 2006 - 09:34 AM

<?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 :)

#6 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 09:40 AM

The problem is still with the original row

Try copying and pasting this into it...

if ((empty($_POST['user'])) && (empty($_POST['pass']))) {

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 14 September 2006 - 10:07 AM

Try this:
<?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>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users