Sorry, I didn't even notice that. It looks like the forum software put the underscores in there. Maybe because I'm on a Mac?
ERRORS:
Right now it's "Column count doesn't match value count at row 1", but that's to be expected.
My form page has 21 text inserts and 10 file uploads (full form here). I need to be able to get all of this information and insert it in one pass.
IN TESTING:
If I use a form that will only update images (img form here) The insert goes well and the images are uploaded and placed in ther respective fields.
If I use the FULL form (full form here), then I get the column count error, etc.
Here's the script again:
<?php
require_once('../Connections/conn_ns.php');
mysql_select_db($database_conn_ns, $conn_ns);
$query_rs_globals = "SELECT sitePath FROM globals";
$rs_globals = mysql_query($query_rs_globals, $conn_ns) or die(mysql_error());
$row_rs_globals = mysql_fetch_assoc($rs_globals);
$totalRows_rs_globals = mysql_num_rows($rs_globals);
$sitePath = $row_rs_globals['sitePath'];
$today = date("YmdGis");
$title = $_POST['title'];
$pod1Head = $_POST['pod1Head'];
$pod1Link = $_POST['pod1Link'];
$pod1Txt = $_POST['pod1Txt'];
$pod2Head = $_POST['pod2Head'];
$pod2Link = $_POST['pod2Link'];
$pod2Txt = $_POST['pod2Txt'];
$pod3Head = $_POST['pod3Head'];
$pod3Link = $_POST['pod3Link'];
$pod3Txt = $_POST['pod3Txt'];
$pod4Head = $_POST['pod4Head'];
$pod4Link = $_POST['pod4Link'];
$pod4Txt = $_POST['pod4Txt'];
$pod5Link = $_POST['pod5Link'];
$pod6Link = $_POST['pod6Link'];
$headline1 = $_POST['headline1'];
$article1 = $_POST['article1'];
$headline2 = $_POST['headline2'];
$article2 = $_POST['article2'];
$headline3 = $_POST['headline3'];
$article3 = $_POST['article3'];
$today = date("YmdGis");
$title = stripslashes($title);
$pod1Head = stripslashes($pod1Head);
$pod1Link = stripslashes($pod1Link);
$pod1Txt = stripslashes($pod1Txt);
$pod2Head = stripslashes($pod2Head);
$pod2Link = stripslashes($pod2Link);
$pod2Txt = stripslashes($pod2Txt);
$pod3Head = stripslashes($pod3Head);
$pod3Link = stripslashes($pod3Link);
$pod3Txt = stripslashes($pod3Txt);
$pod4Head = stripslashes($pod4Head);
$pod4Link = stripslashes($pod4Link);
$pod4Txt = stripslashes($pod4Txt);
$pod5Link = stripslashes($pod5Link);
$pod6Link = stripslashes($pod6Link);
$headline1 = stripslashes($headline1);
$article1 = stripslashes($article1);
$headline2 = stripslashes($headline2);
$article2 = stripslashes($article2);
$headline3 = stripslashes($headline3);
$article3 = stripslashes($article3);
$action = $_POST['action'];
if ($action == "create")
{
//create a new directory with today's date to store the uploads
$img_dir = $sitePath."/images/".$today."/";
mkdir("$img_dir", 0777);
}
if ($action == "edit")
{
$id = $_POST['id'];
$folder = $_POST['folder'];
$img_dir = $sitePath."/images/".$folder."/";
}
$files = $HTTP_POST_FILES[$key];
$fileNames = $_POST['name'];
// upload the picture. Do while one or more upload-files are present
while(list($key) = each($HTTP_POST_FILES))
{
if(isset($HTTP_POST_FILES[$key]['tmp_name']) && $HTTP_POST_FILES[$key]['tmp_name'] != "none")
{
// check the file type to stop unwanted uploads. this will only upload jpeg and gif files
// add other types if you like (i.e. 'application/pdf').
$accepted_types = array('image/jpeg', 'image/jpg', 'image/pjpeg', 'image/gif');
if(!in_array($HTTP_POST_FILES[$key]['type'], $accepted_types) || trim($HTTP_POST_FILES[$key]['tmp_name']) == "" || trim($HTTP_POST_FILES[$key]['tmp_name']) =="none")
{
echo '<center><br /><br /><h1><font face="Verdana, sans-serif" color="red">
ERROR!</font></h1><br><font face="Verdana, sans-serif">You did not supply a valid file.
ALL photos must be in JPEG or GIF format.<br />Please use your <strong>back</strong> button and try again.</font></center>';
exit;
}
// create the destination path
$destination = "$img_dir".$HTTP_POST_FILES[$key]['name'];
// move the uploaded picture from the temp directory to the final destination
move_uploaded_file($HTTP_POST_FILES[$key]['tmp_name'], $destination);
$files = $files.','.$key;
$fileNames = $fileNames.',"'.$_FILES[$key]['name'].'"';
}
}
$files = substr($files,1);
$fileNames = substr($fileNames,1);
// creating a new newsletter
if ($action == "create")
{
$sql = mysql_query("INSERT INTO newsletter (id, title, $files) VALUES ('', '$title', '$fileNames')") or die (mysql_error());
}
//editing a newsletter
if ($action == "edit")
{
$sql = mysql_query("UPDATE newsletter SET files='$files', fileNames='$filenames' WHERE id = '$id'") or die (mysql_error());
}
?>
THANK YOU! 🙂