Page 1 of 1

validation problem

Posted: Thu Aug 03, 2006 1:04 pm
by eektech909
i have an admin page setup to add shows. i'm tryingto validate the text boxes so nothing can be left blank but it keeps adding the info whether the a box is blank or not.
here's the code. help please

Code: Select all

<?php 
session_start();
if(!session_is_registered('myusername')){
header("location:index.htm");
}
if (isset($_POST['submit'])) {
ob_start();
$host="localhost";
$username="root";
$password="8154646";
$db_name="sbaker";
$yearfield=$_POST['yearfield'];
$monthfield=$_POST['monthfield'];
$dayfield=$_POST['dayfield'];
$statefield=$_POST['statefield'];

if ($_POST['venuefield'] !== NULL) {
$venuefield=$_POST['venuefield'];
}else{
$error = 'Please enter a venue';
}
if ($_POST['cityfield'] !== NULL) {
$cityfield=$_POST['cityfield'];
}else{
$error = 'Please enter a city';
}
if ($_POST['playing'] !== NULL) {
$playing=$_POST['playing'];
}else{
$error = 'Please enter the other bands you are playing with';
}
if ($_POST['infofield'] !== NULL) {
$infofield=$_POST['infofield'];
}else{
$error = 'Please enter some show information';
}

if ($error == NULL) {
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql = "INSERT INTO Shows SET " .
	"DATE='$yearfield-$monthfield-$dayfield', " .
	"VENUE='$venuefield', " .
	"CITY='$cityfield, $statefield', " .
	"PLAYINGWITH='$playing', " .
	"INFO='$infofield'";
if (mysql_query($sql)) {
	echo("<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td><div align='center'><font face='verdana' size='1' color='red'><b>Your new show information has been added!</b><br><br></font></div></td></tr></table>");
$yearfield=NULL;
$monthfield=NULL;
$dayfield=NULL;
$venuefield=NULL;
$infofield=NULL;
$playing=NULL;
$cityfield=NULL;
$statefield=NULL;
} else {
	echo("<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td><div align='center'><font face='verdana' size='1' color='red'><b>ERROR ADDING NEW SHOW INFORMATION</b><br><br></font></div></td></tr></table>");
}
ob_end_flush();
}else{
echo $error;
ob_end_flush();
}
}
?>

Posted: Thu Aug 03, 2006 1:21 pm
by feyd

Code: Select all

!isset($error)