doesn't insert if a field is blank
Posted: Tue May 05, 2009 11:51 am
I forgot how to do this, but I don't want it to insert a record if a field is blank.
Every time I try to do what I think is correct, it makes the form disappear.
Here's what I have:
Is that right?
Every time I try to do what I think is correct, it makes the form disappear.
Here's what I have:
Code: Select all
<?php
if ($_POST['pick'] == "") {
$msg = "You need to enter a pick.";
}
if ($_POST) {
$msg="";
include 'dbconn.php';
$enddate=$_POST['enddate'];
$endDateTmp=strtotime($enddate);
$sqldate=strftime('%Y-%m-%d',$endDateTmp);
$insert = "insert ignore into testpick (pick,expiretime,expiredate,starttime) values ('$_POST[pick]','$_POST[endtime]','$sqldate','$_POST[starttime]')";
print $insert;
mysql_query($insert)
or die(mysql_error());
$msg = "You have created a new pick.";
}
else
{
$msg = "There was an error inserting the pick.";
}
//print if it failed or not
echo "<div class=\"error\">$msg</div>";
?>