I've searched on the Internet to get my answer, but I couldn't find a helpful one. I've got a page called 'post.php' with a form where I can add an image and submit it to the database.
The big problem is when I go to mysite.com/post.php a new empty row is created automatically in the database, which I clearly don't want. I want only to update the database after clicking on the submit button my code:
the part of INSERT:
<?php
// POST.PHP POSTING NEW CONTENT
include 'config.php';
                            // values from form
                            $id=$_POST['id'];
                            $title=$_POST['title'];
                            $pic=$_POST['pic'];
                            $youtube=$_POST['youtube'];
                            $cat=$_POST['cat'];
                            // insert data to mysql
                            $sql = "INSERT INTO post(id, title, pic, youtube, cat)VALUES('$id', '$title', '$pic', '$youtube', '$cat')";
                            $result=mysql_query($sql);
                            // succes added
                            if(!$result){
                            echo "Something went wrong!";
                            }
                            else {
                            echo "Yeah, buddy! Your content is added.";
                            }
                            // end of post script ^^
?> 
// end of insert
        //POST IMAGE PAGE
        if(isset($_GET['pic'])) { 
        ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    title: <input name="title" type="text" id="title"><br />
   Add url of image;<br />
    <input type="text" name="pic" id="pic"/><br />
    <?php
    echo '
    Category game: 
     <select name="cat"> ';
     $query2 = mysql_query("SELECT * FROM `category`");
      while($row=mysql_fetch_array($query2)){ 
echo '
       <option value="'.$row["nameID"].'">'.$row["name"].'</option> ';
        } 
    ?>
     </select>
    <input type="submit" onclick="this.disabled = true" name="submit" value="submit">
   </form> 
   <?php
   // end script of posting picture
  }
 ?>
 
     
     
     
     
    