validation problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eektech909
Forum Commoner
Posts: 34
Joined: Fri Jun 09, 2006 3:59 pm

validation problem

Post 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();
}
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

!isset($error)
Post Reply