emediastudios Posted June 5, 2008 Share Posted June 5, 2008 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. Quote Link to comment Share on other sites More sharing options...
emediastudios Posted June 5, 2008 Author Share Posted June 5, 2008 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>"; Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 5, 2008 Share Posted June 5, 2008 <? 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. Quote Link to comment Share on other sites More sharing options...
emediastudios Posted June 6, 2008 Author Share Posted June 6, 2008 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
Buddski Posted June 6, 2008 Share Posted June 6, 2008 Change $id=$_POST['id']; to $id=$_GET['id']; And youll be good to go Quote Link to comment Share on other sites More sharing options...
emediastudios Posted June 6, 2008 Author Share Posted June 6, 2008 Change $id=$_POST['id']; to $id=$_GET['id']; And youll be good to go Thanks that fixed it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.