?
Solved

URGENT : How can I make a delete Item for this page? php/mysql 500points

Posted on 2004-09-28
5
Medium Priority
?
223 Views
Last Modified: 2012-05-05
I need to make a function to delete the item. It has a modify item, but i need to beable to delete it from the database.
I have alrdy added the button, but all my attempts to add the function has failed.

Thanks

------modifyitem.php ------



<?php include("header.php"); ?>
<script language="javascript">
      <!--
      toggle('sub2')
      //-->
</script>
<?php

//print_r($_REQUEST);

      $db = db_connect();
      if (!$db)
      {
            include("footer.php");
            return;
      }

      if ($_REQUEST[pid] == "updateItem")
      {

            /* TODO: some error checking */
            if (isset($_REQUEST[itmid]) && is_numeric($_REQUEST[itmid]))
                  $itemPK = $_REQUEST[itmid];
            else {
                  echo "<p>Invalid or no item supplied. Quitting...</p>\n";
                  include("footer.php");
                  exit;
            }

            $type = addslashes($_REQUEST[tp]);
            $itemID = addslashes($_REQUEST[itid]);
            $invoicePrefix = addslashes($_REQUEST[prfx]);
            $tosTmpl = addslashes($_REQUEST[tos]);
            $formTmpl = addslashes($_REQUEST[frm]);
            $emailTmpl = addslashes($_REQUEST[em]);
            $receiptTmpl = addslashes($_REQUEST[rcpt]);
            $shortDescription = addslashes($_REQUEST[sd]);
            $longDescription = addslashes($_REQUEST[ld]);
            $passwordScript = addslashes($_REQUEST[pwdloc]);
            $memberArea = addslashes($_REQUEST[mbrurl]);
            $price = addslashes($_REQUEST[pc]);

            /* We are NOT updating referrers here */
            $query = "UPDATE $mySQL_itemTable
                          SET type = '$type',
                                itemID = '$itemID',
                                invoicePrefix = '$invoicePrefix',
                                tosTmpl = '$tosTmpl',
                                formTmpl = '$formTmpl',
                                emailTmpl = '$emailTmpl',
                                receiptTmpl = '$receiptTmpl',
                                shortDescription = '$shortDescription',
                                longDescription = '$longDescription',
                                passwordScript = '$passwordScript',
                                memberArea = '$memberArea',
                                price = '$price'
                          WHERE itemsPK = '$itemPK'";
            $result = db_query($query);
            if (!$result)
            {
                  echo "<p class=\"error\">Error in query</p>\n";
                  include("footer.php");
                  exit;
            }

            if (@mysql_affected_rows())
                  echo "<p class=\"success\">Table Successfully Updated!</p>\n";
            else
                  echo "<p class=\"error\">No rows updated.</p>\n";

            include("footer.php");
            exit;
      }
      if (isset($_REQUEST[itid]) && is_numeric($_REQUEST[itid]))
            $itemPK = $_REQUEST[itid];
      else {
            echo "<p>Invalid or no item supplied. Quitting...</p>\n";
            include("footer.php");
            exit;
      }


      $count = 0;
      $templates = Array();
      if ($handle = opendir($template_dir))
      {
            while (false !== ($file = readdir($handle)))
            {
                  if (is_file($template_dir.$file))
                        $templates[$count++] = $file;
            }
      }
      closedir($handle);

      $query = "SELECT * FROM $mySQL_itemTable WHERE itemsPK = '$itemPK'";
      $result = db_query($query);
      if (!$result)
      {
            include("footer.php");
            exit;
      }

      if (@mysql_num_rows($result) > 0)
      {
            $count = 0;
            $referrers = Array();

            $row = @mysql_fetch_array($result);
            $type = $row[type];
            $itemID = $row[itemID];
            $invoicePrefix = $row[invoicePrefix];
            $tosTmpl = $row[tosTmpl];
            $formTmpl = $row[formTmpl];
            $emailTmpl = $row[emailTmpl];
            $receiptTmpl = $row[receiptTmpl];
            $shortDescription = $row[shortDescription];
            $longDescription = $row[longDescription];
            $passwordScript = $row[passwordScript];
            $memberArea = $row[memberArea];
            $price = $row[price];
            $referrers[$count++] = $row[referrer];
            while ($row = @mysql_fetch_array($result))
                  $referrers[$count++] = $row[referrer];

      }

?>
            <script language="javascript">
            <!--
                  function addReferrer()
                  {
                        i = document.getElementById('rfrs').options.length;
                        if (document.addItem.rfr.value != "")
                        {
                              document.getElementById('rfrs').options[i] = new Option(document.addItem.rfr.value, document.addItem.rfr.value);
                              document.getElementById('rfrs').options[i].selected = true;
                        }
                        document.addItem.rfr.value = "";
                  }
            //-->
            </script>

            <h1>Modify Item</h1>

            <p>Use this page to add new service. You can define the cost,
            referrers, templates, etc... from here.</p>

            <div align="center">
            <form method="post" action="<?php echo $PHP_SELF; ?>" name="modifyItem">
            <input type="hidden" name="pid" value="updateItem" />
            <input type="hidden" name="itmid" value="<?php echo $itemPK; ?>" />
            <table border="0" cellspacing="3" cellpadding="0">
                  <tr>
                        <td align="right">Purchase Type</td>
                        <td align="left">
                              <select name="tp">
<?php
      echo "<option value=\"access\"";
      if ($type == "access")
            echo " SELECTED";
      echo ">Access</option>\n";

      echo "<option value=\"service\"";
      if ($type == "service")
            echo " SELECTED";
      echo ">Service</option>\n";
?>
                              </select>
                        </td>
                  </tr>
                  <tr>
                        <td align="right">Item ID</td>
                        <td align="left"><input type="text" name="itid" value="<?php echo $itemID; ?>" size="10" maxlength="25" /></td>
                  </tr>
                  <tr>
                        <td align="right">Invoice Prefix</td>
                        <td align="left"><input type="text" name="prfx" value="<?php echo $invoicePrefix; ?>" size="15" /></td>
                  </tr>
                  <tr>
                        <td align="right=">Terms of Service Template</td>
                        <td align="left">
                              <select name="tos">
                                    <option value="na">Choose Template</option>
                                    <?php
                                          for ($i = 0; $i < sizeof($templates); $i++)
                                          {
                                                      echo "<option value=\"$templates[$i]\"";
                                                      if ($tosTmpl == $templates[$i])
                                                            echo " SELECTED";
                                                      echo ">$templates[$i]</option>\n";
                                          }
                                    ?>
                              </select>
                        </td>
                  </tr>
                  <tr>
                        <td align="right=">Order Form Template</td>
                        <td align="left">
                              <select name="frm">
                                    <option value="na">Choose Template</option>
                                    <?php
                                          for ($i = 0; $i < sizeof($templates); $i++)
                                          {
                                                      echo "<option value=\"$templates[$i]\"";
                                                      if ($formTmpl == $templates[$i])
                                                            echo " SELECTED";
                                                      echo ">$templates[$i]</option>\n";
                                          }
                                    ?>
                              </select>
                        </td>
                  </tr>
                  <tr>
                        <td align="right=">Customer Email Template</td>
                        <td align="left">
                              <select name="em">
                                    <option value="na">Choose Template</option>
                                    <?php
                                          for ($i = 0; $i < sizeof($templates); $i++)
                                          {
                                                      echo "<option value=\"$templates[$i]\"";
                                                      if ($emailTmpl == $templates[$i])
                                                            echo " SELECTED";
                                                      echo ">$templates[$i]</option>\n";
                                          }
                                    ?>
                              </select>
                        </td
                  </tr>
                  <tr>
                        <td align="right=">Receipt Template</td>
                        <td align="left">
                              <select name="rcpt">
                                    <option value="na">Choose Template</option>
                                    <?php
                                          for ($i = 0; $i < sizeof($templates); $i++)
                                          {
                                                      echo "<option value=\"$templates[$i]\"";
                                                      if ($receiptTmpl == $templates[$i])
                                                            echo " SELECTED";
                                                      echo ">$templates[$i]</option>\n";
                                          }
                                    ?>
                              </select>
                        </td>
                  </tr>
                  <tr>
                        <td align="right">Price:</td>
                        <td align="left"><input type="text" name="pc" value="<?php echo $price; ?>" size="15" /></td>
                  </tr>
                  <tr>
                        <td align="right">Billing Type:</td>
                        <td align="left">
                              <select name="bt">
<?php
      echo "<option value=\"One-Time\"";
      if ($billingType == "One-Time")
            echo " SELECTED";
      echo ">One-Time</option>\n";

      echo "<option value=\"Monthly\"";
      if ($billingType == "Monthly")
            echo " SELECTED";
      echo ">Monthly</option>\n";

      echo "<option value=\"Yearly\"";
      if ($billingType == "Yearly")
            echo " SELECTED";
      echo ">Yearly</option>\n";
?>
                              </select>
                        </td>
                  </tr>
                  <tr>
                        <td align="right">Short Description</td>
                        <td align="left"><input type="text" name="sd" value="<?php echo $shortDescription; ?>" size="30" maxlength="100" /></td>
                  </tr>
                  <tr>
                        <td align="right">Long Description:</td>
                        <td align="left"><textarea name="ld" rows="5" cols="20" /><?php echo $longDescription; ?></textarea></td>
                  </tr>
                  <tr>
                        <td colspan="2" align="left"><strong>If the new site is a member access site.</strong></td>
                  </tr>
                  <tr>
                        <td align="right">Password Script Location (URL)</td>
                        <td align="left"><input type="text" name="pwdloc" value="<?php echo $passwordScript; ?>" size="30" /></td>
                  </tr>
                  <tr>
                        <td align="right">Member Area URL</td>
                        <td align="left"><input type="text" name="mbrurl" value="<?php echo $memberArea; ?>" size="30" /></td>
                  </tr>
                  <tr>
                        <td colspan="2" align="center"><input type="submit" value="Update Item" /><input type="submit" value="Delete Item" /></td>
                  </tr>
            </table>
            </form>
            </div>
<?php include("footer.php"); ?>


0
Comment
Question by:Caiapfas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:aratani
ID: 12172567
Don't you have to write the appropriate query to delete from the table,

$query = "DELETE FROM $mySQL_itemTable WHERE itemsPK = '$itemPK'";

Would that do? Be careful that you don't remove the WHERE clause or it would delete everything.

Take care

AJ
0
 
LVL 2

Author Comment

by:Caiapfas
ID: 12173509
ok so how do i make the delete button excute this code?
0
 
LVL 4

Accepted Solution

by:
aratani earned 1000 total points
ID: 12173595
Make the delete button post the form to a page that has this code for deletion. It might post to itself and you might have a form variable saying it was the delete button that was hit.

In your form, you need to fnd out what button was hit. Update or Delete. You could try this,

<input type="submit" name="submit" value="Update Item" /><input type="submit" name="submit" value="Delete Item" />

What does the value of "submit" come up to be in the PHP script after you post it?

echo $_POST ['submit'];

If it can distinguish what button has been pressed, then you could do the following,

if ($_POST ['submit'] == "Update Item") {

  //Code for update
}

else if ($_POST ['submit'] == "Delete Item") {

  //Code for delete
}

AJ
0
 
LVL 2

Author Comment

by:Caiapfas
ID: 12173689
ok thanks but can you add this to the code in the right places for me..i dont understand +}
0
 
LVL 4

Expert Comment

by:aratani
ID: 12219194
oh ... sorry Caiapfas, I just have been really busy, and I forgot about the question you asked. I would have answered your question, if I was given a reminder .. i guess a C is better than nothing ..

anyway, I hope you solved the problem.

AJ
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question