colleyboy Posted September 19, 2010 Share Posted September 19, 2010 Hi... Am trying to add a link to delete a record from the database. think i have it right so far except I cant seem to code this bit right: editshowroom.php echo "<br />"; echo "<br />"; echo "<B><U><I><a href="delete.php?id=<?=$row['id'];?>">DELETE</a></U></I></B>"; <--- coming back with an error! echo "<br />"; echo "<br />"; echo $row['CarTitle']; this is delete.php: if (isset ($_GET['id']) && !empty ($_GET['id'])) { mysql_query ('delete from tablename where id='.intval ($_GET['id']).' limit 1'); header ('showroomconfig.php'); } else { header ('showroomconfig.php'); } exit; Not working atm. can anyone help me. I get the error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/showroomconfig.php on line 83 when opening showroomconfig.php Many Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/ Share on other sites More sharing options...
PaulRyan Posted September 19, 2010 Share Posted September 19, 2010 The snippet from editshowroom.php does not have the correct formatting when echo-ing the delete link Try the follwoing... echo "<br />"; echo "<br />"; echo "<B><U><I><a href='delete.php?id=".$row['id']."'>DELETE</a></U></I></B>"; <--- coming back with an error! echo "<br />"; echo "<br />"; echo $row['CarTitle']; Tell me how is goes buddy Regards, Paul. Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/#findComment-1112783 Share on other sites More sharing options...
colleyboy Posted September 19, 2010 Author Share Posted September 19, 2010 It is loading the page now but i have a new problem. It says: Warning: Cannot modify header information - headers already sent by (output started at /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/delete.php:27) in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/delete.php on line 55 Any ideas dude. Here is delete.php in full if it helps: <HTML> <HEAD> <TITLE>Barry Ottley Motor Co - Quality Used Motors - Stanford-Le-Hope, Essex</TITLE> </HEAD> <BODY LINK="#000000" ALINK="#000000" VLINK="#000000"> <CENTER><IMG SRC="logo.jpg"></CENTER> <CENTER> <TABLE WIDTH="840" CELLPADDING="0" CELLSPACING="0" BORDER="0"> <TR> <TD WIDTH="186" valign="top"> <BR> <CENTER><A HREF="index.html"><IMG SRC="homepage.jpg" alt="Homepage" border="0"></A></CENTER> <CENTER><A HREF="showroom.php"><IMG SRC="showroom.jpg" alt="Our Online Showroom" border="0"></A></CENTER> <CENTER><A HREF="location.html"><IMG SRC="ourlocation.jpg" alt="Our location" border="0"></A></CENTER> <CENTER><A HREF="aboutus.html"><IMG SRC="aboutus.jpg" alt="About Us" border="0"></A></CENTER> <CENTER><A HREF="contactus.php"><IMG SRC="contactus.jpg" alt="Contact Us" border="0"></A></CENTER> </TD> <TD WIDTH="30" valign="top"> </TD> <TD valign="top"> <FONT SIZE="2" FACE="ARIAL"> <CENTER><A HREF="addcar.html"><IMG SRC="vehicleadd.jpg" border="0"></A><A HREF="showroomconfig.php"><IMG SRC="vehicleedit.jpg" border="0"></A><A HREF="showroomconfig.php"><IMG SRC="vehicledelete.jpg" border="0"></A></CENTER> <CENTER><B>Vehicle Added</B></CENTER> <BR> <?php mysql_connect("localhost", "wormste1_barry", "barry") or die(mysql_error()); mysql_select_db("wormste1_barry") or die(mysql_error()); if (isset ($_GET['id']) && !empty ($_GET['id'])) { mysql_query ('delete from tablename where id='.intval ($_GET['id']).' limit 1'); header ('showroomconfig.php'); } else { header ('showroomconfig.php'); } exit; ?> </TD> </TR> </TABLE> <BR><BR><BR><BR> <CENTER><FONT FACE="VERDANA" SIZE="1"> This website was designed and is hosted by <A HREF="http://www.IRCDirect.co.uk">IRC Direct Website Design™</A> 2010 </CENTER> <BR> <CENTER><A HREF="admin.php">Employee Area</A> </BODY> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/#findComment-1112784 Share on other sites More sharing options...
colleyboy Posted September 19, 2010 Author Share Posted September 19, 2010 ok i changed "tablename" to "cars" as thats the tables name. BUT... it DOES delete it from table. but still gives this error: Warning: Cannot modify header information - headers already sent by (output started at /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/delete.php:27) in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/delete.php on line 55 Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/#findComment-1112786 Share on other sites More sharing options...
PaulRyan Posted September 19, 2010 Share Posted September 19, 2010 Thats a simple error... You cannot send out a header request after you have output any characters to the page, it will always return an error. If the delete.php file is just for deleting and nothing else use the following... File: delete.php <?php mysql_connect("localhost", "wormste1_barry", "barry") or die(mysql_error()); mysql_select_db("wormste1_barry") or die(mysql_error()); // added a check to make sure id is a number if(isset ($_GET['id']) && !empty ($_GET['id']) && is_numeric($_GET['id'])){ mysql_query ('DELETE FROM `cars` WHERE id='.intval ($_GET['id']).' LIMIT 1'); header ('showroomconfig.php'); } else { header ('showroomconfig.php'); } exit; ?> Tell me what happens Regards, Paul. Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/#findComment-1112788 Share on other sites More sharing options...
colleyboy Posted September 19, 2010 Author Share Posted September 19, 2010 Hi Paul, Still getting an error mate. Warning: Cannot modify header information - headers already sent by (output started at /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/delete.php:27) in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/delete.php on line 54 I cant think of anything im parsing through the server and asking to print. Hmm is definitely the words. Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/#findComment-1112790 Share on other sites More sharing options...
PaulRyan Posted September 19, 2010 Share Posted September 19, 2010 Sorry, I don't think I was clear enough in my above post I meant for you to dis-regard all of the HTML as you won't ever see it as you are passing a header to redirect to editshowroom.php after any processing is done. Just remove everything from delete.php and put the above code in by itself. Regards, Paul. Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/#findComment-1112792 Share on other sites More sharing options...
colleyboy Posted September 19, 2010 Author Share Posted September 19, 2010 Ok I have removed all code so that: editshowroom.php is still the same delete.php only contains the following: <?php mysql_connect("localhost", "wormste1_barry", "barry") or die(mysql_error()); mysql_select_db("wormste1_barry") or die(mysql_error()); // added a check to make sure id is a number if(isset ($_GET['id']) && !empty ($_GET['id']) && is_numeric($_GET['id'])){ mysql_query ('DELETE FROM `cars` WHERE id='.intval ($_GET['id']).' LIMIT 1'); header ('showroomconfig.php'); } else { header ('showroomconfig.php'); } exit; ?> Still get an error of: Warning: Cannot modify header information - headers already sent by (output started at /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/delete.php:2) in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/delete.php on line 8 Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/#findComment-1112794 Share on other sites More sharing options...
PaulRyan Posted September 19, 2010 Share Posted September 19, 2010 Sorry my mistake, I missed out the Location: part of the header... Try this... <?php mysql_connect("localhost", "wormste1_barry", "barry") or die(mysql_error()); mysql_select_db("wormste1_barry") or die(mysql_error()); // added a check to make sure id is a number if(isset ($_GET['id']) && !empty ($_GET['id']) && is_numeric($_GET['id'])){ mysql_query ('DELETE FROM `cars` WHERE id='.intval ($_GET['id']).' LIMIT 1'); header ("Location: showroomconfig.php"); } else { header ("Location: showroomconfig.php"); } exit; ?> Regards, Paul. Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/#findComment-1112795 Share on other sites More sharing options...
colleyboy Posted September 19, 2010 Author Share Posted September 19, 2010 lovely... deletes the record and reloads the page! perfect. When they click the delete link is there any way of adding a pop up saying... Are you sure then when they click yes it then goes to delete.php. Just thinking about it and I can imagine this fella doing that then ringin me lol! Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/#findComment-1112796 Share on other sites More sharing options...
PaulRyan Posted September 19, 2010 Share Posted September 19, 2010 Glad I could help Yeah it can be done try the following on editshowroom.php in place of the code I gave you a few posts ago. echo "<br />"; echo "<br />"; echo "<B><U><I><a href='javascript:void();' onClick=\"if(confirm('Are you sure you wish to delete this record?')) { location.replace('delete.php?id=".$row['id']."') };\">DELETE</a></U></I></B>"; echo "<br />"; echo "<br />"; echo $row['CarTitle']; Tell me the results bud. Thanks, Paul. Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/#findComment-1112798 Share on other sites More sharing options...
colleyboy Posted September 19, 2010 Author Share Posted September 19, 2010 1 word about that... AWESOME =D! Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/#findComment-1112802 Share on other sites More sharing options...
jcbones Posted September 19, 2010 Share Posted September 19, 2010 Glad I could help Yeah it can be done try the following on editshowroom.php in place of the code I gave you a few posts ago. echo "<br />"; echo "<br />"; echo "<B><U><I><a href='javascript:void();' onClick=\"if(confirm('Are you sure you wish to delete this record?')) { location.replace('delete.php?id=".$row['id']."') };\">DELETE</a></U></I></B>"; echo "<br />"; echo "<br />"; echo $row['CarTitle']; Tell me the results bud. Thanks, Paul. Alternately, a shorter way would be. echo "<br />"; echo "<br />"; echo "<B><U><I><a href='delete.php?id=".$row['id']."' onClick=\"return confirm('Are you sure you wish to delete this record?');\">DELETE</a></U></I></B>"; echo "<br />"; echo "<br />"; echo $row['CarTitle']; Quote Link to comment https://forums.phpfreaks.com/topic/213807-problem-with-deletephpid-parse-error/#findComment-1112903 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.