Jump to content

[SOLVED] Delete Record


emediastudios

Recommended Posts

Sorry to sound stupid but im a newbie to php.

 

I built this code last night and it works for me, I just wanted to add a delete function,

How would i do that if i wanted to filter through the acn_abn field?

 

 

Code below

 <?PHP
    $query = "SELECT * FROM salon_accounts";
    $result = mysql_query($query) or die(mysql_error());
     while ($row = mysql_fetch_array($result)) 
{
  echo "<table width='800'>
  <tr>
  <td width='200' class='borderbold'>Company name</td>
  <td class='border'>$row[company_name]</td><tr>
  <td class='borderbold'>Trading name</td><td class='border'>$row[trading_name]</tr></tr>
  <td class='borderbold'>acn abn</td><td class='border'>$row[acn_abn]</tr></tr>
  <td class='borderbold'>Street address</td><td class='border'>$row[street_address]</tr></tr>
  <td class='borderbold'>Postal address</td><td class='border'>$row[postal_address]</tr></tr>
  <td class='borderbold'>Owners name</td><td class='border'>$row[owner_name]</tr></tr>
  <td class='borderbold'>Contact number</td><td class='border'>$row[contact_number]</tr></tr>
  <td class='borderbold'>E-mail</td><td class='border'>$row[email]</tr></tr>
  <td class='borderbold'>Salon website</td><td class='border'>$row[salon_website]</tr></tr>
  <td class='borderbold'>Contact method</td><td class='border'>$row[contact_method]</tr></tr>
  <td class='borderbold'>Contact time</td><td class='border'>$row[contact_time]</tr></tr>
  <td class='borderbold'>Survey</td><td class='border'>$row[survey]</tr></tr>
  <td class='borderbold'>Comments</td><td class='border'>$row[comments]</tr></tr>
  </table> <br/>";
  

}
?>

Thanks anyone that can help.

I figure i get this one formatted as i wish i will have no trouble altering my code to suit the other four files i need to do the same on.

 

Link to comment
Share on other sites

I have altered my code to this but it doesnt delte the record

this is my delete file code.

 

<? 
session_start();
if(!session_is_registered(user)){
header("location:admin.php");
}
include('includes/include.php');

#Form has been submitted?
if(isset($_GET['action']))
{
   $action=addslashes($_GET['action']);
}

if ( $action == "delete" ) {
$id=$_POST['$row id'];
$query = "DELETE FROM salon_accounts WHERE id='$id'";
$result = mysql_query($query) or die(mysql_error());

echo "deleted";
}
?>

 

and this is the form'

 

echo "<form action='delete_links.php' method='post' target='_self'><br><h3>Salon Application # $row[id]<h3><table width='800' class='border'>
  <tr>
  <td width='200' class='td2'>Company name :</td>
  <td class='td1'>$row[company_name]</td><tr>
  <td class='td2'>Trading name :</td><td class='td1'>$row[trading_name]</tr></tr>
  <td class='td2'>acn abn :</td><td class='td1'>$row[acn_abn]</tr></tr>
  <td class='td2'>Street address :</td><td class='td1'>$row[street_address]</tr></tr>
  <td class='td2'>Postal address :</td><td class='td1'>$row[postal_address]</tr></tr>
  <td class='td2'>Owners name :</td><td class='td1'>$row[owner_name]</tr></tr>
  <td class='td2'>Contact number :</td><td class='td1'>$row[contact_number]</tr></tr>
  <td class='td2'>E-mail :</td><td class='td1'>$row[email]</tr></tr>
  <td class='td2'>Salon website :</td><td class='td1'>$row[salon_website]</tr></tr>
  <td class='td2'>Contact method :</td><td class='td1'>$row[contact_method]</tr></tr>
  <td class='td2'>Contact time :</td><td class='td1'>$row[contact_time]</tr></tr>
  <td class='td2'>Survey :</td><td class='td1'>$row[survey]</tr></tr>
  <td class='comments1'>Comments :</td><td class='comments'>$row[comments]</tr></tr>
  </table> <br/><a href='delete_links.php?action=delete&id=$row[id]'>DELETE FILE</a></form>";

Link to comment
Share on other sites

<? 
session_start();
if(!session_is_registered(user)){
header("location:admin.php");
}
include('includes/include.php');

#Form has been submitted?
if(isset($_GET['action']))
{
   $action=addslashes($_GET['action']);
}

if ( $action == "delete" ) {
$id=$_POST['$row id'];
$query = "DELETE FROM salon_accounts WHERE id='$id'";
mysql_query($query) or die(mysql_error());

echo "deleted";
}
?>

You never ran the query.

Link to comment
Share on other sites

I changed my delete code to

<? 
session_start();
if(!session_is_registered(user)){
header("location:admin.php");
}
include('includes/include.php');

#Form has been submitted?
if(isset($_GET['action']))
{
   $action=addslashes($_GET['action']);
}

if ( $action == "delete" ) {
$id=$_POST['id'];
$query = "DELETE FROM salon_accounts WHERE id='$id'";
mysql_query($query) or die ( "Query failed due to: ".mysql_error());

echo "deleted";
}
?>

But still doesnt delete record.

 

Echos deleted but record remains.

 

Could it have something to do with the $row.

 

Here is the form again

 

<?PHP
    $query = "SELECT * FROM salon_accounts";
    $result = mysql_query($query) or die(mysql_error());
     while ($row = mysql_fetch_array($result)) 
{
  echo "<form action='delete_links.php' method='post' target='_self'><br><h3>Salon Application # $row[id]<h3><table width='800' class='border'>
  <tr>
  <td width='200' class='td2'>Company name :</td>
  <td class='td1'>$row[company_name]</td><tr>
  <td class='td2'>Trading name :</td><td class='td1'>$row[trading_name]</tr></tr>
  <td class='td2'>acn abn :</td><td class='td1'>$row[acn_abn]</tr></tr>
  <td class='td2'>Street address :</td><td class='td1'>$row[street_address]</tr></tr>
  <td class='td2'>Postal address :</td><td class='td1'>$row[postal_address]</tr></tr>
  <td class='td2'>Owners name :</td><td class='td1'>$row[owner_name]</tr></tr>
  <td class='td2'>Contact number :</td><td class='td1'>$row[contact_number]</tr></tr>
  <td class='td2'>E-mail :</td><td class='td1'>$row[email]</tr></tr>
  <td class='td2'>Salon website :</td><td class='td1'>$row[salon_website]</tr></tr>
  <td class='td2'>Contact method :</td><td class='td1'>$row[contact_method]</tr></tr>
  <td class='td2'>Contact time :</td><td class='td1'>$row[contact_time]</tr></tr>
  <td class='td2'>Survey :</td><td class='td1'>$row[survey]</tr></tr>
  <td class='comments1'>Comments :</td><td class='comments'>$row[comments]</tr></tr>
  </table> <br/><a href='delete_links.php?action=delete&id=$row[id]'>DELETE FILE</a></form>";
  

}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.