Validation problem - Beginner
Posted: Thu May 05, 2005 8:55 am
Hi,
I have a small problem that I have tried for sometime to avoid posting but
alas I need to call for assistance.
Basically I have a form with 2 fields one for word document to be uploaded
and the other for the title text of this document to be added to the
database.
All of this works fine in that the upload is carried out ok but I'm running
into problems when trying to set up some validation. At the moment if both
fields are left blank nothing as expected is passed to the database or
folder under the root once the submit button is hit. But if I try to upload
an incorrect file such as an image (along with filling out some text in the
second field of the form) this displays an error telling me that the file
cannot be uploaded again as expected but if I have any text in the other
field this gets passed to the database when it shouldn't.
At the moment I'm using this bit if code (which is one of many different
attempts):
...But ($_POST['userfile]' simply is being ignored.
Later in my code I'm using this..
..and I can see that I need to have some way of running my insert after this
bit of script has run and again I have tried something like this:
...But again this still will creates the same problem.
Can anyone see what I need to do because as I say I can't seem to find a
successful resolution in that if I get one section sorted some other part of
the validation goes astray.
Thanks a mil for reading this long post.
This is a page with the full code from my page just in case it will help
clear up my plea!
http://www.ahamay.com/validation.htm
Brian
I have a small problem that I have tried for sometime to avoid posting but
alas I need to call for assistance.
Basically I have a form with 2 fields one for word document to be uploaded
and the other for the title text of this document to be added to the
database.
All of this works fine in that the upload is carried out ok but I'm running
into problems when trying to set up some validation. At the moment if both
fields are left blank nothing as expected is passed to the database or
folder under the root once the submit button is hit. But if I try to upload
an incorrect file such as an image (along with filling out some text in the
second field of the form) this displays an error telling me that the file
cannot be uploaded again as expected but if I have any text in the other
field this gets passed to the database when it shouldn't.
At the moment I'm using this bit if code (which is one of many different
attempts):
Code: Select all
<?PHP
$nomessage = '';
$nomessage_name = '' ;
// Check each field and build errors array if problems found
if ($_POST && array_key_exists('upload',$_POST)) {
if (isset($_POST['wordDetails']) && !empty($_POST['wordDetails'])) {
$wordDetails=trim($_POST['wordDetails']);
}
else {
$nomessage_name = '<b>Opps! TITLE REQUIRED <b>';
}
if (!empty($_POST['wordDetails']) && !empty($_POST['userfile'])) {
} else echo 'test';
}Later in my code I'm using this..
Code: Select all
//File Size Check
if ( $_FILES['userfile']['size'] > $MAX_SIZE)
$message = "The file size is over 2MB.";
//File Type/Extension Check
else if (!in_array($file_type, $FILE_MIMES)
&& !in_array($file_ext, $FILE_EXTS) )
$message = "Sorry, $file_name($file_type) is not allowed to be
uploaded.";
else
$message = do_upload($upload_dir, $upload_url);..and I can see that I need to have some way of running my insert after this
bit of script has run and again I have tried something like this:
Code: Select all
//File Size Check
if ( $_FILES['userfile']['size'] > $MAX_SIZE)
$message = "The file size is over 2MB.";
//File Type/Extension Check
else if (!in_array($file_type, $FILE_MIMES)
&& !in_array($file_ext, $FILE_EXTS) )
$message = "Sorry, $file_name($file_type) is not allowed to be
uploaded.";
else
$message = do_upload($upload_dir, $upload_url);
if ((isset($_POST["upload"])) && ($_POST["upload"] == "form1")) {
if (!$nomessage && !$nomessage_name) {
$insertSQL = sprintf("INSERT INTO word (wordName, wordDetails) VALUES (%s,
%s)",
GetSQLValueString($_FILES['userfile']['name'],
"text"),
GetSQLValueString($_POST['wordDetails'], "text"));
mysql_select_db($database_johnston, $johnston);
$Result1 = mysql_query($insertSQL, $johnston) or die(mysql_error());
}}Can anyone see what I need to do because as I say I can't seem to find a
successful resolution in that if I get one section sorted some other part of
the validation goes astray.
Thanks a mil for reading this long post.
This is a page with the full code from my page just in case it will help
clear up my plea!
http://www.ahamay.com/validation.htm
Brian