-2

I am trying to make a php script which will accept a password text and will delete the relevant data from the database. I get this error when i load the script

syntax error, unexpected T_IS_NOT_EQUAL in /home2/krisindi/public_html/deletead.php on line 4

    <?php
$password = $_POST["password"];

if ( $password ) != 0 )
        {
                $id = $data->select ("Classified", "AdID", array ("Password => ($password)));
                $data->delete ( "AdExtraField" , array ( "AdID" => intval ( $id["AdID"] ) ) ) ;
                $data->delete ( "Classified" , array ( "Password" => ( $password ) ) ) ;
                exec ( "chmod ../media/ 777" ) ;

                $image_file = "../media/cls_".$id["AdID"]."_520.jpg" ;
                if ( file_exists ( $image_file ) )
                        unlink ( $image_file ) ;

                for ( $i = 1 ; $i <= 5 ; $i++ )
                {
                        $image_file = "../media/cls_".$id["AdID"]."_".$i."_520.jpg" ;
                        if ( file_exists ( $image_file ) )
                                unlink ( $image_file ) ;
                }

                exec ( "chmod ../media/ 755" ) ;

                $_SESSION["str_system_message"] = "Classified deleted successfully." ;
        }

?>

<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
Password:<input type="text" size="12" maxlength="12" name="password">:<br />
<input type="submit" value="submit" name="submit"><br />
</form><br />

2 Answers 2

7

Line 4:

    <?php
$password = $_POST["password"];

if ( $password ) != 0 )
               ^
               Mismatched parenthesis

Update

Given that the question is getting negative votes, I'll improve my answer to make it more generalizable. You get a syntax error when your PHP code is not even valid PHP code (normally, because of a typo). In such case, the code won't even start running. Applied to the current situation, the first conclusion is that it doesn't matter what the script tries to accomplish since it will never run until you fix the syntax error.

Now, what does the error mean. Let's analyse it:

syntax error, unexpected T_IS_NOT_EQUAL in /home2/krisindi/public_html/deletead.php on line 4

Bit by bit:

syntax error,

Invalid PHP. The script cannot be executed.

unexpected T_IS_NOT_EQUAL

If has found a T_IS_NOT_EQUAL token. In plain English, it means that is has found a != operator in a place where it was not expected.

in /home2/krisindi/public_html/deletead.php on line 4

This is the exact file and line number where the error was detected. It doesn't mean that the error is there but it's a good place to star. If your editor cannot display line numbers switch to a better editor.

Now, let's look at line 4:

if ( $password ) != 0 )
                 ^
                 T_IS_NOT_EQUAL

Here's the T_IS_NOT_EQUAL token. Why is it unexpected? Because once you've closed the if() construct you have to either open a block with { or type a valid PHP sentence. No valid PHP sentence can start with != thus the error.

3
  • It's not your answer, your answer is correct and now even great with the update. It's about the question itself, pasting a block of code and saying "Here's my code, please fix it" is not a question which belongs here, especially if it is such an obvious problem which should already get caught at IDE level. To me this looks like the OP didn't bother looking for the problem himself.
    – Bobby
    Commented Jan 4, 2011 at 14:54
  • @Bobby I actually aimed to make the question more generalizable, not the answer. I agree with you anyway. Commented Jan 4, 2011 at 15:04
  • Oh, I see, sorry if I got you wrong.
    – Bobby
    Commented Jan 4, 2011 at 15:08
0

@krisdigitx: Line 6

$id = $data->select("Classified", "AdID", array("Password => ($password)));

is missing a "

$id = $data->select("Classified", "AdID", array("Password" => ($password)));

Not the answer you're looking for? Browse other questions tagged or ask your own question.