Do not put into database if there is no entry.

Discussion in 'PHP' started by baris22, Feb 17, 2009.

  1. #1
    hello,

    I have got a form with 3 fields (20 form on 1 page). Sometimes there is no entry on title field but there is entry on description and fullpage fields. All i want to do is if there is no entry on title i just do not want to put it into database.

    How can i do this?

    
    
        $title=$_POST['title'][$i];
        $description=$_POST['description'][$i];
        $fullpage=$_POST['fullpage'][$i];
    
    		
    
                    $query="INSERT INTO `file` VALUES ('', '".$title."', '".$description."', '".$fullpage."')";
        mysql_query($query);
        echo mysql_error();
        $c++;
       }
      }
      echo '<center><b>'. $c.' entries put into database</b></center><br/>';
      mysql_close($link);
     }
    
    
    PHP:
    Thanks
     
    baris22, Feb 17, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    if(empty($title) || empty($description) || empty($fullpage)) exit;
     
    crivion, Feb 17, 2009 IP
  3. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #3
    if (empty($title) || empty($description) || empty($fullpage)) {
    // redirect or exit script
    }
    
    // or
    
    if ($title=="" || $description=="" || $fullpage=="") {
    // redirect or exit script
    }
    PHP:
     
    ActiveFrost, Feb 17, 2009 IP