Jump to content

Multiple Insert Functions Problem


amwd07

Recommended Posts

Hello I have the following issue.

 

I have recently created a bespoke admin script, eveything works except when my client comes to insert more than 1 PDF

here's my script, which I will try & expalin step by step how this works so someone is either going to help me or poin tout the ovious  :-[

 

First off instead of having the standard browse & upload method to insert pdf into the DB I have created a media Library, which allows my client to select an image or in this case a PDF to insert in to the venue's listing.

 

the problem is when I select a PDF which displays in the dropdown options if I select the file from the dropdown this then updates the DB, everything is OK up to this point but as soon as I select another PDF ie. a venue listing has the option for 2 for each section tab.

without going in to to much detail I will get right down to explining my problem.

 

I have included a seperate file in my venue update page with all the pdf fuctions in, this is called select-pdf.php

 

contents of select-pdf.php

<?php 
$dine = $_GET['dine_id'];
$dirname = "/usr/home/virtuals/web/comedinewithus/outlet/id/$dine/";
$actpath = $dirname;

///// Offers PDF 1 /////	
function offerPDF1($path){
echo "<div class=library_files>";
echo "<select name='special_offer_pdf1' id='special_offer_pdf1'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){ 
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Offers PDF 2 /////
function offerPDF2($path){
echo "<div class=library_files>";
echo "<select name='special_offer_pdf2' id='special_offer_pdf2'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){ 
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Events PDF 1 /////
function eventPDF1($path){
echo "<div class=library_files>";
echo "<select name='event_pdf1' id='event_pdf1'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){ 
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Events PDF 2 /////
function eventPDF2($path){
echo "<div class=library_files>";
echo "<select name='event_pdf2' id='event_pdf2'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){ 
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Menus PDF 1 /////
function menuPDF1($path){
echo "<div class=library_files>";
echo "<select name='menu_pdf1' id='menu_pdf1'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){ 
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Menus PDF 2 /////
function menuPDF2($path){
echo "<div class=library_files>";
echo "<select name='menu_pdf2' id=menu_pdf2'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){ 
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Reviews PDF 1 /////
function reviewsPDF1($path){
echo "<div class=library_files>";
echo "<select name='reviews_pdf1' id='reviews_pdf1'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){ 
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// Reviews PDF 2 /////
function reviewsPDF2($path){
echo "<div class=library_files>";
echo "<select name='reviews_pdf2' id='reviews_pdf2'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){ 
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// News PDF 1 /////
function newsPDF1($path){
echo "<div class=library_files>";
echo "<select name='news_pdf1' id='news_pdf1'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){ 
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";

///// News PDF 2 /////
function newsPDF2($path){
echo "<div class=library_files>";
echo "<select name='news_pdf2' id='news_pdf2'>";
echo "<option value='' selected='selected'>None</option>";
if ($handle = opendir($path)){
while (false !== ($file = readdir($handle))){ 
if (strpos($file, '.pdf',1)){
$dine = $_GET['dine_id'];
$fName = $file;
$file = $path.'/'.$file;
if(is_file($file)) {
echo "<option value='$fName'>$fName</option>";}}}
closedir($handle);}}echo "</select></div>";
?>

 

 

 

now on the venue update page I have the following lines which inserts into the DB, I know this part works as this is addon the dreamweaver CS3

 

// Make an update transaction instance
$upd_restaurant_extras = new tNG_update($conn_connDW);
$tNGs->addTransaction($upd_restaurant_extras);
// Register triggers
$upd_restaurant_extras->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1");
// Add columns
$upd_restaurant_extras->setTable("restaurant_extras");
$upd_restaurant_extras->addColumn("special_offer_url", "STRING_TYPE", "POST", "special_offer_url");
$upd_restaurant_extras->addColumn("special_offer_pdf1", "STRING_TYPE", "POST", "special_offer_pdf1");
$upd_restaurant_extras->addColumn("special_offer_pdf1_title", "STRING_TYPE", "POST", "special_offer_pdf1_title");
$upd_restaurant_extras->addColumn("special_offer_pdf2", "STRING_TYPE", "POST", "special_offer_pdf2");
$upd_restaurant_extras->addColumn("special_offer_pdf2_title", "STRING_TYPE", "POST", "special_offer_pdf2_title");
$upd_restaurant_extras->addColumn("event_url", "STRING_TYPE", "POST", "event_url");
$upd_restaurant_extras->addColumn("event_pdf1_title", "STRING_TYPE", "POST", "event_pdf1_title");
$upd_restaurant_extras->addColumn("event_pdf2_title", "STRING_TYPE", "POST", "event_pdf2_title");
$upd_restaurant_extras->addColumn("event_pdf1", "STRING_TYPE", "POST", "event_pdf1");
$upd_restaurant_extras->addColumn("event_pdf2", "STRING_TYPE", "POST", "event_pdf2");
$upd_restaurant_extras->addColumn("menu_url", "STRING_TYPE", "POST", "menu_url");
$upd_restaurant_extras->addColumn("menu_pdf1", "STRING_TYPE", "POST", "menu_pdf1");
$upd_restaurant_extras->addColumn("menu_pdf1_title", "STRING_TYPE", "POST", "menu_pdf1_title");
$upd_restaurant_extras->addColumn("menu_pdf2", "STRING_TYPE", "POST", "menu_pdf2");
$upd_restaurant_extras->addColumn("menu_pdf2_title", "STRING_TYPE", "POST", "menu_pdf2_title");
$upd_restaurant_extras->addColumn("reviews_url", "STRING_TYPE", "POST", "reviews_url");
$upd_restaurant_extras->addColumn("reviews_pdf1", "STRING_TYPE", "POST", "reviews_pdf1");
$upd_restaurant_extras->addColumn("reviews_pdf1_title", "STRING_TYPE", "POST", "reviews_pdf1_title");
$upd_restaurant_extras->addColumn("reviews_pdf2", "STRING_TYPE", "POST", "reviews_pdf2");
$upd_restaurant_extras->addColumn("reviews_pdf2_title", "STRING_TYPE", "POST", "reviews_pdf2_title");
$upd_restaurant_extras->addColumn("news_url", "STRING_TYPE", "POST", "news_url");
$upd_restaurant_extras->addColumn("news_pdf1", "STRING_TYPE", "POST", "news_pdf1");
$upd_restaurant_extras->addColumn("news_pdf1_title", "STRING_TYPE", "POST", "news_pdf1_title");
$upd_restaurant_extras->addColumn("news_pdf2", "STRING_TYPE", "POST", "news_pdf2");
$upd_restaurant_extras->addColumn("news_pdf2_title", "STRING_TYPE", "POST", "news_pdf2_title");
$upd_restaurant_extras->setPrimaryKey("dine_id", "NUMERIC_TYPE", "GET", "dine_id");

 

Now further down the page this is how I call the function please excuse the messy table layout not had time to tidy this up  :(

 

<table border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#F4F4F4">
<?php if (@$totalRows_offerstab != 0 ) { ?>
<tr>
<td bgcolor="#FFCC00"><label for="hometab_featured"><strong>Activate:</strong></label></td>
<td bgcolor="#FFFFFF"><input  <?php if (!(strcmp(KT_escapeAttribute($row_rsrestaurants['hometab_special_offer']),"1"))) {echo "checked";} ?> type="checkbox" name="hometab_special_offer" id="label" value="1" />
<?php echo $tNGs->displayFieldError("restaurants", "hometab_special_offer"); ?></td>
</tr>
<?php } ?>
  <tr bordercolor="#FFFFFF" bgcolor="#F4F4F4">
  <td bgcolor="#FFEEAA"><strong>Offer Teaser: </strong></td>
<td bgcolor="#FFEEAA"><input type="text" name="special_offer_text" id="special_offer_text" value="<?php echo KT_escapeAttribute($row_rsrestaurants['special_offer_text']); ?>" size="60" />
  <?php echo $tNGs->displayFieldHint("special_offer_text");?> <?php echo $tNGs->displayFieldError("restaurants", "special_offer_text"); ?></td>
  </tr>
  <tr>
  <td><label for="special_offer_url">Offer Web link:</label></td>
<td><input type="text" name="special_offer_url" id="special_offer_url" value="<?php echo KT_escapeAttribute($row_rsrestaurant_extras['special_offer_url']); ?>" size="50" />
  <?php echo $tNGs->displayFieldHint("special_offer_url");?> <?php echo $tNGs->displayFieldError("restaurant_extras", "special_offer_url"); ?> </td>
  </tr>
    
  <tr>
  <td><label for="special_offer_pdf1_title">Offer PDF Title 1:</label></td>
<td><input type="text" name="special_offer_pdf1_title" id="special_offer_pdf1_title" value="<?php echo KT_escapeAttribute($row_rsrestaurant_extras['special_offer_pdf1_title']); ?>" size="50" />
  <?php echo $tNGs->displayFieldHint("special_offer_pdf1_title");?> <?php echo $tNGs->displayFieldError("restaurant_extras", "special_offer_pdf1_title"); ?> </td>
  </tr>
  <tr>
  <td><label for="special_offer_pdf2_title">Offer PDF Title 2:</label></td>
<td><input type="text" name="special_offer_pdf2_title" id="special_offer_pdf2_title" value="<?php echo KT_escapeAttribute($row_rsrestaurant_extras['special_offer_pdf2_title']); ?>" size="50" />
  <?php echo $tNGs->displayFieldHint("special_offer_pdf2_title");?> <?php echo $tNGs->displayFieldError("restaurant_extras", "special_offer_pdf2_title"); ?> </td>
  </tr>
<tr>
<td><label for="offer_pdf1">Select PDF 1:</label></td>
<?php if (@$offerpdf1 != "") {
echo "<td>";
echo "<a href='/outlet/id/$dine/$offerpdf1' target='_blank'>"."<b>".$offerpdf1."</b></a>";
echo "<span class='delete'>";
echo "<input name='offer_pdf1' type='checkbox' value=''/>";
echo " "."Delete PDF";
echo "</span>";
echo "</td>";
} else { 
echo "<td>";
offerPDF1($actpath);
echo "</td>"; 
} ?>
</tr>
<tr>
<td><label for="offer_pdf2">Select PDF 2:</label></td>
<?php if (@$offerpdf2 != "") {
echo "<td>";
echo "<a href='/outlet/id/$dine/$offerpdf2' target='_blank'>"."<b>".$offerpdf2."</b></a>";
echo "<span class='delete'>";
echo "<input name='offer_pdf2' type='checkbox' value=''/>";
echo " "."Delete PDF";
echo "</span>";
echo "</td>";
} else { 
echo "<td>";
offerPDF2($actpath);
echo "</td>"; 
} ?>
</tr>
  <tr>
    <td> </td>
  <td><div align="right">
    <input type="submit" name="KT_Update1" id="KT_Update1" value="Update" />
    </div></td>
  </tr>
  </table>

 

 

rather than posting the above several times i will just show you snipets of code for each venues section

 

<?php if (@$eventpdf1 != "") {
echo "<td>";
echo "<a href='/outlet/id/$dine/$eventpdf1' target='_blank'>"."<b>".$eventpdf1."</b></a>";
echo "<span class='delete'>";
echo "<input name='event_pdf1' type='checkbox' value=''/>";
echo " "."Delete PDF";
echo "</span>";
echo "</td>";
} else { 
echo "<td>";
eventPDF1($actpath);
echo "</td>"; 
} ?>

<?php if (@$eventpdf2 != "") {
echo "<td>";
echo "<a href='/outlet/id/$dine/$eventpdf2' target='_blank'>"."<b>".$eventpdf2."</b></a>";
echo "<span class='delete'>";
echo "<input name='event_pdf2' type='checkbox' value=''/>";
echo " "."Delete PDF";
echo "</span>";
echo "</td>";
} else { 
echo "<td>";
eventPDF2($actpath);
echo "</td>"; 
} ?>

<?php if (@$menupdf1 != "") {
echo "<td>";
echo "<a href='/outlet/id/$dine/$menupdf1' target='_blank'>"."<b>".$menupdf1."</b></a>";
echo "<span class='delete'>";
echo "<input name='menu_pdf1' type='checkbox' value=''/>";
echo " "."Delete PDF";
echo "</span>";
echo "</td>";
} else { 
echo "<td>";
menuPDF1($actpath);
echo "</td>"; 
} ?>

<?php if (@$menupdf2 != "") {
echo "<td>";
echo "<a href='/outlet/id/$dine/$menupdf2' target='_blank'>"."<b>".$menupdf2."</b></a>";
echo "<span class='delete'>";
echo "<input name='menu_pdf2' type='checkbox' value=''/>";
echo " "."Delete PDF";
echo "</span>";
echo "</td>";
} else { 
echo "<td>";
menuPDF2($actpath);
echo "</td>"; 
} ?>

 

and it goes on you get the idea, these functions seem to overide each other for example if I update menus 1 pdf this is Ok but when I add pdf 2 this overides this, also it overides the others section PDF, there must be soemthing wrong in the function coding.

Please I really hope someone has a good idea to what I am talking about.

 

Thank you in advanced  ;)

Link to comment
https://forums.phpfreaks.com/topic/112815-multiple-insert-functions-problem/
Share on other sites

OK the functions found in my first block of code individually work for each PDF selcted in the dropdown but when I go to insert a second PDF it overides the first  ???

 

Maybe there is something wrong with my function somewhere  ???

 

ie, dreamweaver developer toolbox inserts into the DB.

 

// Make an update transaction instance
$upd_restaurant_extras = new tNG_update($conn_connDW);
$tNGs->addTransaction($upd_restaurant_extras);
// Register triggers
$upd_restaurant_extras->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1");
// Add columns
$upd_restaurant_extras->setTable("restaurant_extras");

$upd_restaurant_extras->addColumn("special_offer_pdf1", "STRING_TYPE", "POST", "special_offer_pdf1");
$upd_restaurant_extras->addColumn("special_offer_pdf2", "STRING_TYPE", "POST", "special_offer_pdf2");
$upd_restaurant_extras->addColumn("event_pdf1", "STRING_TYPE", "POST", "event_pdf1");
$upd_restaurant_extras->addColumn("event_pdf2", "STRING_TYPE", "POST", "event_pdf2");
$upd_restaurant_extras->addColumn("menu_pdf1", "STRING_TYPE", "POST", "menu_pdf1");
$upd_restaurant_extras->addColumn("menu_pdf2", "STRING_TYPE", "POST", "menu_pdf2");
$upd_restaurant_extras->addColumn("reviews_pdf1", "STRING_TYPE", "POST", "reviews_pdf1");
$upd_restaurant_extras->addColumn("reviews_pdf2", "STRING_TYPE", "POST", "reviews_pdf2");
$upd_restaurant_extras->addColumn("news_pdf1", "STRING_TYPE", "POST", "news_pdf1");
$upd_restaurant_extras->addColumn("news_pdf2", "STRING_TYPE", "POST", "news_pdf2");
$upd_restaurant_extras->setPrimaryKey("dine_id", "NUMERIC_TYPE", "GET", "dine_id");

RightI have almost got this now

 

changed my function to the following.

 

///// Offers PDF 1 ///// 
function offerPDF1($path){ 
$out = ''; 
if ($handle = opendir($path)){ 
$out.= "<div class=library_files>"; 
$out.= "<select name='special_offer_pdf1' id='special_offer_pdf1'>"; 
$out.= "<option value='' selected='selected'>None</option>"; 
while (false !== ($file = readdir($handle))){ 
if (strpos($file, '.pdf',1)){ 
$dine = $_GET['dine_id']; 
$fName = $file; 
$file = $path.'/'.$file; 
if(is_file($file)) { 
$out.= "<option value='$fName'>$fName</option>"; 
} 
} 
} 
closedir($handle); 
$out.= "</select></div>"; 
} 
else { 
$out.= 'Error.<br />'; 
$out.= "Handle: $handle <br />Path: $path<br />"; 
} 
return $out; 
} 

 

 

and all I am now doing to call this function further down the page is

 

<?php 
echo "<td>"; 
offerPDF1($actpath); 
echo "</td>"; 
?> 

 

but this still doesn't work infact the dropdowns have disapeared, but I think I am now on the right track, please someone here help  ???

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.