why are these first three isset's being ignored? these variables are taken from a form that was just submitted. I'm trying to make sure that if any of these three fields are blank, that the database INSERT code following doesn't run, and reloads the addNewClient.php. but it always runs, adding a new blank row to my database. as a side note, if i fill out the form, it INSERTS the data flawlessly, so what did i forget?
cheers!
Jason
<?php
//checking for required field input.
if ( isset( $username ) and isset( $password ) and isset( $clientname ) ) {
//setting checkbox values
if ( ! empty( $accesscal ) ) {
$accesscal = "Y";
} else {
$accesscal = "N";
}
if ( ! empty( $accessnote ) ) {
$accessnote = "Y";
} else {
$accessnote = "N";
}
if ( ! empty( $accessrec ) ) {
$accessrec = "Y";
} else {
$accessrec = "N";
}
$dberror = " ";
$ret = add_to_database( $username, $password, $clientname, $email, $phone,
$fax, $address1, $address2, $city, $state, $zip,
$accesscal, $accessnote, $accessrec, &$dberror );
if ( ! $ret ) {
print "Error: $dberror<BR>";
} else {
header( "Location: viewClients.php" );
}
} else {
header( "Location: addNewClient.php" );
}
function add_to_database( $username, $password, $clientname, $email, $phone,
$fax, $address1, $address2, $city, $state, $zip,
$accesscal, $accessnote, $accessrec, &$dberror ) {
$user = "cpoint";
$pass = "damon";
$database = "counterpoint";
$link = mysql_connect( "localhost", $user, $pass );
if ( ! $link ) {
$dberror = "Couldn't connect to MySQL server.";
return false;
}
if ( ! mysql_select_db( $database, $link ) ) {
$dberror = mysql_error();
return false;
}
$query = "INSERT INTO clients ( username, password, clientname, email, phone, fax,
address1, address2, city, state, zip, accesscal, accessnote, accessrec )
VALUES( '$username', '$password', '$clientname', '$email', '$phone', '$fax',
'$address1', '$address2', '$city', '$state', '$zip',
'$accesscal', '$accessnote', '$accessrec' )";
if ( ! mysql_query( $query, $link ) ) {
$dberror = mysql_error();
return false;
}
return true;
}
mysql_close( $link );
?>