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

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"); ?>


LVL 2
CaiapfasAsked:
Who is Participating?
 
arataniConnect With a Mentor Commented:
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
 
arataniCommented:
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
 
CaiapfasAuthor Commented:
ok so how do i make the delete button excute this code?
0
 
CaiapfasAuthor Commented:
ok thanks but can you add this to the code in the right places for me..i dont understand +}
0
 
arataniCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.