I am having problems with a form that submits information using php 4.2.2. Here is what happens. When I submit a post through the form, the from should post the info to the php script and then the php script should insert it inot the database. The pageid for the page that it is updating info for is calculated from the id that is passed through the browser. When I try to query the database the only thing that is inserted in the database is the pageid. Also, images are not submitting to the database? Can anyone help?
Here is part of the script.
<?php
include "../../xtemplate/xtemplate.class.php";
include "../../include/error.inc";
include "../../include/include.inc";
// Initialize an error string
$errorString = "";
$id = (int) isSet($_GET['id']) ? $_GET['id'] : 0;
$pageid = $id + 99;
$picid = $id + 99;
$cat = 22;
// A fucntion to determine the type of the images
function picture1($type, $picture1, $ext, $connection)
{
//get info about the image being uploaded
list($type, $ext) = getimagesize($picture1);
switch ($type)
{
case 1:
$ext = ".gif";
break;
case 2:
$ext = ".jpg";
break;
case 3:
$ext = ".swf";
break;
default:
echo "Sorry, but the file you uploaded was not a GIF, JPG, or " .
"SWF file.<br>";
echo "Please hit your browser's 'back' button and try again.";
}
}
// Clear and register an error array
$_SESSION["pageErrors"] = array();
// Set up the pageForm array for the POST variables
$_SESSION["pageFormVars"] = array();
// Clean and trim the POSTed values MAY not need this or may have to do this another way
foreach($_POST as $varname => $value)
$_SESSION["pageFormVars"]["{$varname}"] = trim(clean($_POST, $varname, $value, 50, $connection));
// Validate the home, about, and native anmerican categories apges
if (($id == 1) || ($id == 3) || ($id >= 5) && ($id <= $cat))
{
// Validate a form field
if (empty($_SESSION["pageFormVars"]["pgtitle"]))
// The pgtitle for the home page cannot be NULL
$errorString .= "\n<br>The pgtitle field cannot be blank.";
}
// Now the script has finished validation,
// Check if there were any errors
if (count($_SESSION["pageErrors"]) > 0)
{
// Redirect the browser to the calling page
header("Location: $HTTP_REFERER");
exit;
}
// If we made it here, then the data is valid
if (!($connection = @ mysql_pconnect($hostName,
$username,
$password)))
die("Could not connect to the database");
if (!mysql_select_db($databaseName, $connection))
showerror();
// Check to see if the pageid is in the database
if ($result = @ mysql_query ("SELECT pageid FROM pages, pgcontact, pgmission
WHERE pageid = $pageid", $connection))
{
if (($id == 1) || ($id == 3) || ($id >= 5) && ($id <= $cat))
{
// update required fields
if (!($result = @ mysql_query ("UPDATE pages SET
pgtitle = '{$_SESSION["pageFormVars"]["pgtitle"]}',
pgdesc = '{$_SESSION["pageFormVars"]["pgdesc"]}',
kywd1 = '{$_SESSION["pageFormVars"]["kywd1"]}',
kywd2 = '{$_SESSION["pageFormVars"]["kywd2"]}',
kywd3 = '{$_SESSION["pageFormVars"]["kywd3"]}',
kywd4 = '{$_SESSION["pageFormVars"]["kywd4"]}',
kywd5 = '{$_SESSION["pageFormVars"]["kywd5"]}',
kywd6 = '{$_SESSION["pageFormVars"]["kywd6"]}',
kywd7 = '{$_SESSION["pageFormVars"]["kywd7"]}',
kywd8 = '{$_SESSION["pageFormVars"]["kywd8"]}',
kywd9 = '{$_SESSION["pageFormVars"]["kywd9"]}',
kywd10 = '{$_SESSION["pageFormVars"]["kywd10"]}',
kywd11 = '{$_SESSION["pageFormVars"]["kywd11"]}',
kywd12 = '{$_SESSION["pageFormVars"]["kywd12"]}',
heading = '{$_SESSION["pageFormVars"]["heading"]}',
subheading = '{$_SESSION["pageFormVars"]["subheading"]}',
paragraph1 = '{$_SESSION["pageFormVars"]["paragraph1"]}',
paragraph2 = '{$_SESSION["pageFormVars"]["paragraph2"]}',
paragraph3 = '{$_SESSION["pageFormVars"]["paragraph3"]}',
paragraph4 = '{$_SESSION["pageFormVars"]["paragraph4"]}',
picturetext1 = '{$_SESSION["pageFormVars"]["picturetext1"]}',
picturetext2 = '{$_SESSION["pageFormVars"]["picturetext2"]}',
WHERE pageid = {$pageid}", $connection)))
showerror();
// update picture 1
if (is_uploaded_file($_FILES["picture1"]["pic1"]))
{
picture1($type, $picture1, $ext, $connection);
if (!($result = @ mysql_query ("UPDATE picture set
picture1 = '{$_FILE["pageFormVars"]["picture1"]}'
WHERE picid = {$pageid}", $connection)))
showerror();
}
elseif (!($result = @ mysql_query ("SELECT pageid FROM pages, pgcontact, pgmission
WHERE pageid = $pageid", $connection)))
{
if (($id == 1) || ($id == 3) || ($id >= 5) && ($id <= $cat))
{
// insert required fields
if (!($result = @ mysql_query ("INSERT INTO pages VALUES ({$pageid},
'{$_SESSION["pageFormVars"]["pgtitle"]}',
'{$_SESSION["pageFormVars"]["pgdesc"]}',
'{$_SESSION["pageFormVars"]["pgname"]}',
'{$_SESSION["pageFormVars"]["kywd1"]}',
'{$_SESSION["pageFormVars"]["kywd2"]}',
'{$_SESSION["pageFormVars"]["kywd3"]}',
'{$_SESSION["pageFormVars"]["kywd4"]}',
'{$_SESSION["pageFormVars"]["kywd5"]}',
'{$_SESSION["pageFormVars"]["kywd6"]}',
'{$_SESSION["pageFormVars"]["kywd7"]}',
'{$_SESSION["pageFormVars"]["kywd8"]}',
'{$_SESSION["pageFormVars"]["kywd9"]}',
'{$_SESSION["pageFormVars"]["kywd10"]}',
'{$_SESSION["pageFormVars"]["kywd11"]}',
'{$_SESSION["pageFormVars"]["kywd12"]}',
'{$_SESSION["pageFormVars"]["heading"]}',
'{$_SESSION["pageFormVars"]["subheading"]}',
'{$_SESSION["pageFormVars"]["paragraph1"]}',
'{$_SESSION["pageFormVars"]["paragraph2"]}',
'{$_SESSION["pageFormVars"]["paragraph3"]}',
'{$_SESSION["pageFormVars"]["paragraph4"]}',
'{$_SESSION["pageFormVars"]["picturetext1"]}',
'{$_SESSION["pageFormVars"]["picturetext2"]}')", $connection)))
showerror();
// insert picture 1 & picture 2
if ((is_uploaded_file($_FILES["picture1"]["pic1"])) && (is_uploaded_file($_FILES["picture2"]["pic2"])))
{
picture1($type, $picture1, $ext, $connection);
picture2($type, $picture1, $ext, $connection);
if (!($result = @ mysql_query ("INSERT INTO picture VALUES ({$picid}, {$pageid},
'{$_FILE["pageFormVars"]["picture1"]}',
'{$_FILE["pageFormVars"]["picture2"]}')", $connection)))
showerror();
}
}
if (count($_SESSION["pageErrors"]) > 0)
{
// There are errors. Relocate back to the client form
header("Location: $HTTP_REFERER");
exit;
}
}
}
else
{
if (count($_SESSION["pageErrors"]) > 0)
{
// There are errors. Relocate back to the client form
header("Location: $HTTP_REFERER");
exit;
}
}
// Now show the confirmation page
// header("Location: confirmation.php");
?>