Forum Moderators: coopster

Message Too Old, No Replies

Insertion Problems

Insertion Problem

         

CodeMama

4:19 pm on Nov 7, 2008 (gmt 0)

10+ Year Member



I need some help figuring out why the new fields I added to my script will not work, not only are they not inserting into the db, they are making the whole script which previously worked not run (nothing inserts) but it did previously.
<?php
include("inc/dbconn_open.php");

if (empty($_SESSION['AdminLogin']) OR $_SESSION['AdminLogin'] <> 'OK' ){
header ("Location: LogOut.php");
}

if (isset($_POST['AdminID'])){
$AdminID = $_POST['AdminID'];
} elseif (isset($_GET['AdminID'])){
$AdminID = $_GET['AdminID'];
} else {
header ("Location: LogOut.php");
}

if (!empty($_POST['GO'])){$GO = $_POST['GO'];} else {$GO = "";}
if (isset($_POST['Location'])){$Location = $_POST['Location'];} else {$Location = "";}
if (isset($_POST['WorkOrderName'])){$WorkOrderName = $_POST['WorkOrderName'];} else {$WorkOrderName = "";}
if (!empty($_POST['Customer'])){$Customer = $_POST['Customer'];} else {$Customer = "";}

if (!empty($_POST['AccountNum'])){$AccountNum = $_POST['AccountNum'];} else {$AccountNum = "";}
if (!empty($_POST['IONum'])){$IONum = $_POST['IONum'];} else {$IONum = "";}
if (!empty($_POST['StartMonth']) && !empty($_POST['StartDay']) && !empty($_POST['StartYear'])){
$StartDate = $_POST['StartYear'] ."-". $_POST['StartMonth'] ."-". $_POST['StartDay'];
} else {
$StartDate = "";
}
if (!empty($_POST['EndMonth']) && !empty($_POST['EndDay']) && !empty($_POST['EndYear'])){
$EndDate = $_POST['EndYear'] ."-". $_POST['EndMonth'] ."-". $_POST['EndDay'];
} else {
$EndDate = "";
}
if (!empty($_POST['Headline'])){$Headline = $_POST['Headline'];} else {$Headline = "";}
if (!empty($_POST['Body'])){$Body = $_POST['Body'];} else {$Body = "";}
if (!empty($_POST['URL'])){$URL = $_POST['URL'];} else {$URL = "";}
if (!empty($_POST['SearchTerm1'])){$SearchTerm1 = $_POST['SearchTerm1'];} else {$SearchTerm1 = "";}
if (!empty($_POST['SearchTerm2'])){$SearchTerm2 = $_POST['SearchTerm2'];} else {$SearchTerm2 = "";}
if (!empty($_POST['SearchTerm3'])){$SearchTerm3 = $_POST['SearchTerm3'];} else {$SearchTerm3 = "";}
if (!empty($_POST['SearchTerm4'])){$SearchTerm4 = $_POST['SearchTerm4'];} else {$SearchTerm4 = "";}
if (!empty($_POST['SearchTerm5'])){$SearchTerm5 = $_POST['SearchTerm5'];} else {$SearchTerm5 = "";}
if (isset($_POST['Salesperson'])){$Salesperson = $_POST['Salesperson'];} else {$Salesperson = "";}
if (isset($_POST['SalespersonID'])){$SalespersonID = $_POST['SalespersonID'];} else {$SalespersonID = "";}
if (isset($_POST['SalespersonEmail'])){$SalespersonEmail = $_POST['SalespersonEmail'];} else {$SalespersonEmail = "";}
if (isset($_POST['SalespersonExt'])){$SalespersonExt = $_POST['SalespersonExt'];} else {$SalespersonExt = "";}
if (isset($_POST['Comments'])){$Comments = $_POST['Comments'];} else {$Comments = "";}
if (isset($_POST['ExtraImage1Desc'])){$ExtraImage1Desc = $_POST['ExtraImage1Desc'];} else {$ExtraImage1Desc = "";}
if (isset($_POST['ExtraImage2Desc'])){$ExtraImage2Desc = $_POST['ExtraImage2Desc'];} else {$ExtraImage2Desc = "";}
if (isset($_POST['ExtraImage3Desc'])){$ExtraImage3Desc = $_POST['ExtraImage3Desc'];} else {$ExtraImage3Desc = "";}
if (isset($_POST['ExtraImage4Desc'])){$ExtraImage4Desc = $_POST['ExtraImage4Desc'];} else {$ExtraImage4Desc = "";}
if (isset($_POST['ExtraImage5Desc'])){$ExtraImage5Desc = $_POST['ExtraImage5Desc'];} else {$ExtraImage5Desc = "";}
if (isset($_POST['GiftImage1Desc'])){$GiftImage1Desc = $_POST['GiftImage1Desc'];} else {$GiftImage1Desc = "";}
if ($GO == "Save") {
$sql = "SELECT Name FROM admin WHERE AdminID='$AdminID'";
$result = mysql_query ($sql);
$row = mysql_fetch_object ($result);

$Notes = "~". date("F j, Y g:i a") ." - Planet Discover Right Side Text Ad Submitted by ". $row->Name ."\n";

$sql = "INSERT INTO workorders (CreatedDate, Location, WorkOrderName, AdminID, FormName, Status, Notes) VALUES (";
$sql .= "Now(), '$Location', '$WorkOrderName', '$AdminID', 'PD_TextAd', 'New Order', '$Notes')";
mysql_query($sql);
$WorkOrderID = mysql_insert_id();

if ($_FILES) {
if (isset($_FILES['Logo'])) {
if (is_uploaded_file ($_FILES['Logo']['tmp_name'])) {
$ImageExt = strtolower(end(explode('.', $_FILES['Logo']['name'])));
$Logo = "Artwork/". $WorkOrderID ."_Logo.". $ImageExt;
move_uploaded_file($_FILES['Logo']['tmp_name'],$Logo);
}
}
if (isset($_FILES['ExtraImage1'])) {
if (is_uploaded_file ($_FILES['ExtraImage1']['tmp_name'])) {
$ImageExt = strtolower(end(explode('.', $_FILES['ExtraImage1']['name'])));
$ExtraImage1Name = "Artwork/". $WorkOrderID ."_Image1.". $ImageExt;
move_uploaded_file($_FILES['ExtraImage1']['tmp_name'],$ExtraImage1Name);
}
}
if (isset($_FILES['ExtraImage2'])) {
if (is_uploaded_file ($_FILES['ExtraImage2']['tmp_name'])) {
$ImageExt = strtolower(end(explode('.', $_FILES['ExtraImage2']['name'])));
$ExtraImage2Name = "Artwork/". $WorkOrderID ."_Image2.". $ImageExt;
move_uploaded_file($_FILES['ExtraImage2']['tmp_name'],$ExtraImage2Name);
}
}
if (isset($_FILES['ExtraImage3'])) {
if (is_uploaded_file ($_FILES['ExtraImage3']['tmp_name'])) {
$ImageExt = strtolower(end(explode('.', $_FILES['ExtraImage3']['name'])));
$ExtraImage3Name = "Artwork/". $WorkOrderID ."_Image3.". $ImageExt;
move_uploaded_file($_FILES['ExtraImage3']['tmp_name'],$ExtraImage3Name);
}
}
if (isset($_FILES['ExtraImage4'])) {
if (is_uploaded_file ($_FILES['ExtraImage4']['tmp_name'])) {
$ImageExt = strtolower(end(explode('.', $_FILES['ExtraImage4']['name'])));
$ExtraImage4Name = "Artwork/". $WorkOrderID ."_Image4.". $ImageExt;
move_uploaded_file($_FILES['ExtraImage4']['tmp_name'],$ExtraImage4Name);
}
}
if (isset($_FILES['ExtraImage5'])) {
if (is_uploaded_file ($_FILES['ExtraImage5']['tmp_name'])) {
$ImageExt = strtolower(end(explode('.', $_FILES['ExtraImage5']['name'])));
$ExtraImage5Name = "Artwork/". $WorkOrderID ."_Image5.". $ImageExt;
move_uploaded_file($_FILES['ExtraImage5']['tmp_name'],$ExtraImage5Name);
}
}
if (isset($_FILES['GiftImage1'])) {
if (is_uploaded_file ($_FILES['GiftImage1']['tmp_name'])) {
$ImageExt = strtolower(end(explode('.', $_FILES['GiftImage1']['name'])));
$GiftImage1Name = "Artwork/". $WorkOrderID ."_GImage1.". $ImageExt;
move_uploaded_file($_FILES['GiftImage1']['tmp_name'],$GiftImage1Name);
}
}

}

$sql = "INSERT INTO pd_textad (WorkOrderID, CreatedDate, Customer, AccountNum, IONum, StartDate, EndDate, Headline, Body, ";
$sql .= "Logo, URL, SearchTerm1, SearchTerm2, SearchTerm3, SearchTerm4, SearchTerm5, Salesperson, SalespersonID, ";
$sql .= "SalespersonEmail, SalespersonExt, Comments, ExtraImage1, ExtraImage1Desc, ExtraImage2, ExtraImage2Desc, ";
$sql .= "GiftImage1, GiftImage1Desc,";
$sql .= "ExtraImage3, ExtraImage3Desc, ExtraImage4, ExtraImage4Desc, ExtraImage5, ExtraImage5Desc) VALUES (";
$sql .= "'". mysql_real_escape_string($WorkOrderID) ."', Now(), ";
$sql .= "'". mysql_real_escape_string($Customer) ."', ";
$sql .= "'". mysql_real_escape_string($AccountNum) ."', ";
$sql .= "'". mysql_real_escape_string($IONum) ."', ";
$sql .= "'". mysql_real_escape_string($StartDate) ."', ";
$sql .= "'". mysql_real_escape_string($EndDate) ."', ";
$sql .= "'". mysql_real_escape_string($Headline) ."', ";
$sql .= "'". mysql_real_escape_string($Body) ."', ";
$sql .= "'". mysql_real_escape_string($Logo) ."', ";
$sql .= "'". mysql_real_escape_string($URL) ."', ";
$sql .= "'". mysql_real_escape_string($SearchTerm1) ."', ";
$sql .= "'". mysql_real_escape_string($SearchTerm2) ."', ";
$sql .= "'". mysql_real_escape_string($SearchTerm3) ."', ";
$sql .= "'". mysql_real_escape_string($SearchTerm4) ."', ";
$sql .= "'". mysql_real_escape_string($SearchTerm5) ."', ";
$sql .= "'". mysql_real_escape_string($Salesperson) ."', ";
$sql .= "'". mysql_real_escape_string($SalespersonID) ."', ";
$sql .= "'". mysql_real_escape_string($SalespersonEmail) ."', ";
$sql .= "'". mysql_real_escape_string($SalespersonExt) ."', ";
$sql .= "'". mysql_real_escape_string($Comments) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage1Name) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage1Desc) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage2Name) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage2Desc) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage3Name) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage3Desc) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage4Name) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage4Desc) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage5Name) ."', ";
$sql .= "'". mysql_real_escape_string($ExtraImage5Desc) ."') ";

mysql_query($sql);

$Message = "<HTML>";
$Message.= "<STYLE TYPE=\"text/css\">";
$Message.= "<!--";
$Message.= "body {font-size:12px; font-family:arial, sans-serif;}";
$Message.= "-->";
$Message.= "</STYLE>";
$Message.= "</HEAD>";
$Message.= "<body>";
$Message.= "A Planet Discover Right Side Text Ad form was submitted.";
$Message.= "</body>";
$Message = wordwrap($Message, 70);

$Subject = "Planet Discover Right Side Text Ad Form";
$Email = "email@example.com";

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: email@example.com\r\n";
$headers .= "From: email@example.com\r\n";

@mail($Email, $Subject, $Message, $headers);

?>
<script language="javascript">
alert("Your Planet Discover Right Side Text Ad form has been received. \n\nThank You.");
window.location="Welcome.php?AdminID=<?php echo $AdminID; ?>";
</script>
<?php
exit();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Planet Discover Right Side Text Ad</title>
<LINK REL="STYLESHEET" HREF="inc/style.css">

<script type="text/javascript" language="JavaScript">
// count characters, check for max
function countChars(field, max){
if (field.form.elements[field.name + "Count"]) {
if(field.value.length > max){
field.value = field.value.substr(0,max);
}
field.form.elements[field.name + "Count"].value = field.value.length;
}
}

</script>

<script type=text/javascript>
<!-- // drop open for the gift guide upsale
var DHTML = (document.getElementById ¦¦ document.all ¦¦ document.layers);
function getObj(name){
if (document.getElementById){
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
} else if (document.all) {
this.obj = document.all[name];
this.style = document.all[name].style;
} else if (document.layers) {
this.obj = document.layers[name];
this.style = document.layers[name];
}
}

function change(name) {
var x = new getObj(name);
if (x.style.visibility == 'visible') {
x.style.visibility = 'hidden';
x.style.display = 'none';
} else {
x.style.visibility = 'visible';
x.style.display = '';
}
}

function Show(name){
var x = new getObj(name);x.style.visibility = 'visible'
var x = new getObj(name);x.style.display = ''
}

function Hide(name){
var x = new getObj(name);x.style.visibility = 'hidden'
var x = new getObj(name);x.style.display = 'none'
}

function status(name) {
var x = new getObj(name);
if (x.style.visibility == 'visible') {
return true;
} else {
return false;
}
}

function GiftGuideUpSale(tmp) {
if (tmp == "YES") {
Show('GiftGuideImg');
Show('GiftGuideDesc');

} else {
Hide('GiftGuideImg');
Hide('GiftGuideDesc');

}
}
</script>
</head>


The new fields are the "GiftImage1" and "GiftImage1Desc"
when I add them to the code using the same method as the "ExtraImage" nothing works, please anyone got ideas?

[edited by: eelixduppy at 4:22 pm (utc) on Nov. 7, 2008]
[edit reason] exemplified [/edit]

eelixduppy

4:23 pm on Nov 7, 2008 (gmt 0)



Hello and Welcome to WebmasterWorld! :)

To aid in helping you can you please check your PHP error log (after having turned error reporting up) and give us any errors you are receiving from this script?

CodeMama

5:05 pm on Nov 7, 2008 (gmt 0)

10+ Year Member



Hi and thanks for the welcome!
Well I have added
mysql_query($sql) OR die(mysql_error());
as suggested off another forum to try and see what errors if any are being thrown and nothing happens. I have just realized after doing some test forms, and looking at the Db that the "GiftImage1" is being inserted into the "ExtraImage1" field, so looks like now I have an extra problem, when I did another text, and filled in not only the "GiftImage1" field and the "ExtraImage1" field it still inserted the GiftImage1 into the ExtraImage1 field in the db and inserted the ExtraImage1 into the ExtraImage2 field....should I possibly be adding something to my form fields as to which db fields to insert into, I can't figure out why its putting it in the wrong fields....argh so glad its Friday!