Jump to content

Problem with delete.php?id= - PARSE ERROR???


colleyboy

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'];

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.