Jump to content

Delete entry from the Database


bryanptcs

Recommended Posts

How can I delete an entry from the database from my php page?  My code is below.  I basically am having an admin side where the admin can select an entry and delete it without having to go into the actual db and empty it.  Any suggestions? 

[code] <form class="form" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">

    <p>
      <label for="txtName">Class</label>
      <br />
    <input type="text" title="Enter your name" name="txtClass" /></p>

<p>
  <label for="rate">Date</label>
  <br>
  <input type="text" title="Date" name="txtDate" /> 
  <label for="rate"></label>
  </p>
<p>City<br>
  <input type="text" title="City" name="txtcity" />
  </p>
<p>Contact<br>
  <input type="text" title="contact" name="txtcontact" />
</p>
<p>Contact Email<br>
  <input name="txtemail" type="text" id="txtemail" title="contact" />
  </p>
<p><label title="Send your message">
    <input type="submit" value="Send" />
   
    </label></p><br />
<hr>

   
</form>
<table width="100%" align="center" cellpadding="0" cellspacing="0">
  <tr class="colorbar2">
    <td width="22%"><div align="center"><span class="style3 style4"><strong>Class</strong></span></div></td>
    <td width="16%"><div align="center"><span class="style3 style4"><strong>Date of Class </strong></span></div></td>
    <td width="31%"><div align="center"><span class="style3 style4"><strong>Location of Class</strong></span></div></td>
    <td width="31%"><div align="center"><span class="style3 style4"><strong>Who to Contact</strong></span></div></td>
  </tr></table>
<?php

/**
* Create the table in your MySQL database:
*
* CREATE TABLE guests (
*  id int(10) NOT NULL auto_increment,
*  name varchar(50) NOT NULL,
*  message varchar(255) NOT NULL,
*  date timestamp(14) NOT NULL,
*  PRIMARY KEY (id)
* )
*
* Change the database login settings to your own
*
* The script is now ready to run
*/

// Change these to your own database settings
$host = "";
$user = "";
$pass = "";
$db = "";

mysql_connect($host, $user, $pass) OR die ("Could not connect to the server.");
mysql_select_db($db) OR die("Could not connect to the database.");
     
$class = stripslashes($_POST['txtClass']);
$date = stripslashes($_POST['txtDate']);
$city = stripslashes($_POST['txtcity']);
$contact = stripslashes($_POST['txtcontact']);
$email = stripslashes($_POST['txtemail']);

if (!isset($_POST['txtClass'])) {
$query = "SELECT id, class, date, city, email, contact FROM class";
    $result = mysql_query($query);
   
    while ($row = mysql_fetch_object($result)) {

?>

  <table width="100%" align="center" cellpadding="0" cellspacing="0" border="1">
  <tr><td width="22%">
    <p class="infotext"><?php echo $row->class; ?></p></td>
<td width="16%"><p class="infotext"><?php echo $row->date; ?></p></td>
<td width="31%"><p class="infotext"><?php echo $row->city; ?></p></td>
<td width="31%"><p class="infotext"><a href="mailto:<?php echo $row->email; ?>?subject=<?php echo $row ->class; ?>"><?php echo $row->contact; ?></a> </p></td></tr></table>



 
 
  <?php
       
    }
   
?>





<?php

}

else {

    // Adds the new entry to the database
    $query = "INSERT INTO class SET class='$class', date='$date', city='$city', email='$email', contact='$contact'";
    $result = mysql_query($query);

    // Takes us back to the entries
    $ref = $_SERVER['HTTP_REFERER'];
    header ("Location: $ref");
}

?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/27377-delete-entry-from-the-database/
Share on other sites

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.