-7
<?php   
    include("conn.php");
    if(isset($_POST['save'])){

        $title=$_POST['title'];
        $genre=$_POST['genre'];
        $year=$_POST['year'];

        $sql = "INSERT INTO `add`(`title`, `genre`, `year`) VALUES ('$title','$genre','$year')" ;
            $query = mysql_query($sql);
        if (empty ($_POST["title"] || ["genre"] || ["year"])){
            echo "You did not fill out the required fields.";
        }
        else ($query){
            echo "Successfully Inserted . <a href = 'index.php'> Ok </a>";
        }

    }


?>

Every time I run the code then this is the error stated:

"Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\Practise PHOBIAmming Skills\sample1\add.php on line 24"

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    **WARNING**: If you're just learning PHP, please, do not use the [`mysql_query`](http://php.net/manual/en/function.mysql-query.php) interface. It’s so awful and dangerous that it was removed in PHP 7. A replacement like [PDO is not hard to learn](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/) and a guide like [PHP The Right Way](http://www.phptherightway.com/) explains best practices. Your user data is **not** [properly escaped](http://bobby-tables.com/php.html) and there are [SQL injection bugs](http://bobby-tables.com/) and can be exploited. – tadman Sep 07 '17 at 04:44
  • I don't think your code have 24 lines. Did you hide some part of the code? – Alive to die - Anant Sep 07 '17 at 04:44
  • This is only 21 lines. Remember, indenation is important, it helps you find mistakes like this. – tadman Sep 07 '17 at 04:45
  • 2
    `else ($query)` need to be `else if ($query)` – Alive to die - Anant Sep 07 '17 at 04:47
  • @AlivetoDie I got it. Thanks :) – Mhiathell Rose Anoos Maraveles Sep 07 '17 at 04:52
  • 1
    @MhiathellRoseAnoosMaraveles i will ask you to delete this question then, because it's something like TYPO mistake. And you are loosing your point too due to massive down-vote (may be more will come in near future on this). – Alive to die - Anant Sep 07 '17 at 04:56
  • @AlivetoDie yes I will but how can I delete my post :) – Mhiathell Rose Anoos Maraveles Sep 07 '17 at 05:01
  • @AlivetoDie it was said that I can't delete my post since their are people who answered it already – Mhiathell Rose Anoos Maraveles Sep 07 '17 at 05:11

1 Answers1

1

You have added condition to else

else ($query){

remove it or make it elseif according to your logic

Jigar Shah
  • 6,143
  • 2
  • 28
  • 41
  • yes, I got it. Thanks :) – Mhiathell Rose Anoos Maraveles Sep 07 '17 at 04:51
  • Questions that are about basic PHP syntax errors should not be answered. They should be closed as a duplicate of [PHP Parse/Syntax Errors; and How to solve them?](//stackoverflow.com/questions/18050071) only. See: [Should one advise on off topic questions?](//meta.stackoverflow.com/q/276572/1768232). Off-topic questions can be closed and deleted, which could nullify your contribution anyway. – John Conde Sep 07 '17 at 11:38