-2

I think the insert query should ends with semicolon as the similar code is working for another form. But it shows this error:

PHP Parse error: syntax error, unexpected ';'

Here is my piece of PHP script for insert data into database from a form.

if((!empty($name) && !empty($location) && !empty($fulladdress) && !empty($ownername) && !empty($ownercontact) && !empty(category) && 
                    ($invalidphflag==true) && ($phoneflag==true) && !empty($size) && !empty($price) )
        {
                $insertquery= "INSERT INTO properties (name, location, address, owner_name, owner_no, size, price, category) 
                VALUES ('$name', '$location', '$fulladdress', '$ownername', '$ownercontact', '$size', '$price', '$category')";

            $query = mysqli_query($db, $insertquery);

            if($query)
            {
             $success= "Details submitted successfully.";
            }   



    }
Ravi Sharma
  • 244
  • 2
  • 14
  • 1
    You're missing a parenthesis at the end of your first IF statement. There's no need for all these answers it's one simple typo. – MinistryOfChaps Aug 10 '17 at 09:33

4 Answers4

1
if(!empty($name) && !empty($location) && !empty($fulladdress) && !empty($ownername) && !empty($ownercontact) && !empty($category) &&
    ($invalidphflag==true) && ($phoneflag==true) && !empty($size) && !empty($price) ) {
    $insertquery= "INSERT INTO properties (name, location, address, owner_name, owner_no, size, price, category) 
                VALUES ('$name', '$location', '$fulladdress', '$ownername', '$ownercontact', '$size', '$price', '$category')";

    $query = mysqli_query($db, $insertquery);

    if($query)
    {
        $success= "Details submitted successfully.";
    }
}
Vladislav
  • 357
  • 1
  • 8
1

You have one bracket in your if statement that's not closed.

So your if statement should be like:

 if ((!empty($name) && !empty($location) && !empty($fulladdress) && !empty($ownername) && !empty($ownercontact) && !empty(category) && 
        ($invalidphflag==true) && ($phoneflag==true) && !empty($size) && !empty($price) 
    ))

Resulting in:

 if ((!empty($name) && !empty($location) && !empty($fulladdress) && !empty($ownername) && !empty($ownercontact) && !empty(category) && 
    ($invalidphflag==true) && ($phoneflag==true) && !empty($size) && !empty($price) 
))
{
    $insertquery= "INSERT INTO properties (name, location, address, owner_name, owner_no, size, price, category) 
        VALUES ('$name', '$location', '$fulladdress', '$ownername', '$ownercontact', '$size', '$price', '$category')";

    $query = mysqli_query($db, $insertquery);

    if ($query)
    {
        $success= "Details submitted successfully.";
    }   
}
Vincent Cohen
  • 878
  • 7
  • 28
1
if((!empty($name)
    && !empty($location)
    && !empty($fulladdress)
    && !empty($ownername)
    && !empty($ownercontact)
    && !empty($category)
   )
&&
   ($invalidphflag == true
   && $phoneflag == true
   && !empty($size)
   && !empty($price)
   )){
        $insertquery= "INSERT INTO properties (name, location, address, owner_name, owner_no, size, price, category) 
                VALUES ('$name', '$location', '$fulladdress', '$ownername', '$ownercontact', '$size', '$price', '$category')";
        $query = mysqli_query($db, $insertquery);
        if($query)
        {
           $success= "Details submitted successfully.";
        }   
   }

you have missed $ sign along !empty(category) in first part of condition

Naveed Ramzan
  • 3,565
  • 3
  • 25
  • 30
0

if((!empty($name) && !empty($location) && !empty($fulladdress) && !empty($ownername) && !empty($ownercontact) && !empty(category) && ($invalidphflag==true) && ($phoneflag==true) && !empty($size) && !empty($price) )

Has one more opening bracket ( than closing )

Scoots
  • 3,048
  • 2
  • 21
  • 33