Hi Dagon,
Thanks for your reply. I actually got this to work by using implode. Here's my code in its entirety now.
#connect to the database
mysql_connect("localhost", "root", "m3gatr0n");
mysql_select_db("masscic");
#initialize the variables for the form if users want to post a sighting
$name ='';
$email ='';
$website ='';
$fname ='';
$ftype ='';
$fsize ='';
$tname ='';
$scid ='';
$state ='';
$county ='';
$stown ='';
$street ='';
$sdate ='';
$stemp ='';
$stime ='';
$lat ='';
$lon ='';
$comments ='';
$regExp ='';
$errorMsg ='';
#grab the form data
$curnum = 0; //will itemize the number of errors we have
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$scid = $_POST['category'];
$state = $_POST['state'];
$county = $_POST['county'];
$stown = $_POST['town'];
$street = $_POST['street'];
$sdate = $_POST['sighting_date'];
$stemp = $_POST['temp'];
$stime = $_POST['time'];
$lat = $_POST['latitude'];
$lon = $_POST['longitude'];
$comments = $_POST['description'];
#do some injection cleaning
$name = stripslashes($name);
$email = stripslashes($email);
$website = stripslashes($website);
$state = stripslashes($state);
$county = stripslashes($county);
$stown = stripslashes($stown);
$street = stripslashes($street);
$sdate = stripslashes($sdate);
$stemp = stripslashes($stemp);
$stime = stripslashes($stime);
$lat = stripslashes($lat);
$lon = stripslashes($lon);
$comments = stripslashes($comments);
$name = strip_tags($name);
$email = strip_tags($email);
$website = strip_tags($website);
$state = strip_tags($state);
$county = strip_tags($county);
$stown = strip_tags($stown);
$street = strip_tags($street);
$sdate = strip_tags($sdate);
$stemp = strip_tags($stemp);
$stime = strip_tags($stime);
$lat = strip_tags($lat);
$lon = strip_tags($lon);
$comments = strip_tags($comments);
#verify properly formatted email address
//$regExp = '/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/';
$regExp = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
#check for errors
if (strlen($name) < 2) {
$curnum ++;
$errorMsg['name'] = '<li><span class="error">'.$curnum.'. Your name is required</span></li>';
}
if (!preg_match($regExp, $email)) {
$curnum ++;
$errorMsg['email'] = '<li><span class="error">'.$curnum.'. Please enter a valid email address</span></li>';
}
if (strlen ($scid) < 1) {
$curnum ++;
$errorMsg['category'] = '<li><span class="error">'.$curnum.'. Please choose a sighting type</span></li>';
}
if (strlen ($state) < 1) {
$curnum ++;
$errorMsg['state'] = '<li><span class="error">'.$curnum.'. Please choose a state</span></li>';
}
if (strlen ($stown) < 1) {
$curnum ++;
$errorMsg['town'] = '<li><span class="error">'.$curnum.'. We definately need the town</span></li>';
}
if (strlen ($street) < 1) {
$curnum ++;
$errorMsg['street'] = '<li><span class="error">'.$curnum.'. Please specify the street or location name</span></li>';
}
if (!$sdate) {
$curnum ++;
$errorMsg['sighting_date'] = '<li><span class="error">'.$curnum.'. Need a sighting date</span></li>';
}
$name = mysql_real_escape_string($name);
$email = mysql_real_escape_string($email);
$website = mysql_real_escape_string($website);
$state = mysql_real_escape_string($state);
$county = mysql_real_escape_string($county);
$stown = mysql_real_escape_string($stown);
$street = mysql_real_escape_string($street);
$sdate = mysql_real_escape_string($sdate);
$stemp = mysql_real_escape_string($stemp);
$stime = mysql_real_escape_string($stime);
$lat = mysql_real_escape_string($lat);
$lon = mysql_real_escape_string($lon);
$comments = mysql_real_escape_string($comments);
//Upload Handler
function is_image($file) {
$file_types = array('jpeg', 'gif', 'bmp', 'png'); //acceptable file types
if ($img = getimagesize($file)){
//echo '<pre>';
//print_r($img); will return an array of information for testing
//print_r($_FILES); will return an array of information for testing
if(in_array(str_replace('image/', '', $img['mime']), $file_types))
return $img;
}
return false;
}
//upload files portion of form submission handling
//variables
$fname = $_FILES['files']['name'];
$ftype = $_FILES['files']['type'];
$fsize = $_FILES['files']['size'];
$tname = $_FILES['files']['tmp_name'];
$ferror = $_FILES['files']['error'];
if(isset($_POST['submit'])) {
$newDir = '../uploads/'; //relative to where this script file resides
for($i = 0; $i < count($fname); $i++) {
//echo 'File name ' . $fname[$i] . ' has size ' . $fsize[$i]; used for testing
//for ($i = count($fname) -1; $i >=0; $i--) {
if ($ferror[$i] =='UPLOAD ERR OK' || $ferror[$i] ==0)
{
if(is_image($tname[$i]))
{
move_uploaded_file($tname[$i], ($newDir.time().$fname[$i]));
echo '<li><span class="success">'.$fname[$i].' -- image has been accepted<br></span></li>';
}else
echo '<li><span class="error">'.$fname[$i].' -- is not an accepted file type<br></span></li>';
}
//*****************This Line of code fixed my problem********************//
if (is_array($fname))
$files = implode(', ',$fname);
}
}
#done with error checking now perform the insert
if (!$errorMsg) {
$sqlInsert = mysql_query("INSERT INTO usersightings
(entry_date,
scid,
name,
email,
website,
files,
state,
county,
town,
street,
sighting_date,
temp,
time,
lat,
lng,
description)
VALUES( now(),
'$scid',
'$name',
'$email',
'$website',
'$files',
'$state',
'$county',
'$stown',
'$street',
'$sdate',
'$stemp',
'$stime',
'$lat',
'$lon',
'$comments')") or die (mysql_error());
echo '<li class="success"> Congratulations, ' . $name . '. Your data was posted successfully! You will receive an email shortly </li>';
}
else {
$response = (isset($errorMsg['name'])) ? "<li>" . $errorMsg['name'] . "</li> \n" : null;
$response .= (isset($errorMsg['email'])) ? "<li>" . $errorMsg['email'] . "</li> \n" : null;
$response .= (isset($errorMsg['category'])) ? "<li>" . $errorMsg['category'] . "</li>" : null;
$response .= (isset($errorMsg['state'])) ? "<li>" . $errorMsg['state'] . "</li>" : null;
$response .= (isset($errorMsg['town'])) ? "<li>" . $errorMsg['town'] . "</li>" : null;
$response .= (isset($errorMsg['street'])) ? "<li>" . $errorMsg['street'] . "</li>" : null;
$response .= (isset($errorMsg['sighting_date'])) ? "<li>" . $errorMsg['sighting_date'] . "</li>" : null;
echo $response;
} # end if there was an error posting
My next problem is trying to sort out if the user leaves an empty input form field with type="file" attribute I want it to throw an error but I can't seem to do it for $FILES only $POST variables. Any suggestions?
Thanks
Gerry