Jump to content

DELETE FROM not working


dolcezza

Recommended Posts

Can anyone please help me figure out why this isn't working? I am new at this and having alot of trouble. I get a blank page, not even an error.

$id = $_GET[id];
$query = "DELETE FROM contacts WHERE id='$id'";
$result = mysql_query($query) or die ("Error in query: $query.".mysql_error());

I'm getting the id from

<a href='delete.php?id=<?=$id;?>'>delete</a>

 

Thanks!

Link to comment
Share on other sites

the record isn't getting deleted from database.

full code on that page:

<?php
include_once("connect.php")
$id = $_GET[id];
$query = "DELETE FROM contacts WHERE id='$id'";
$result = mysql_query($query) or die ("Error in query: $query.".mysql_error());

 

full code from page where id is coming from:

<?php
include_once("connect.php");
$id=$_GET['id'];


$query="SELECT * FROM contacts ORDER BY last ASC";
$result=mysql_query($query);
// count how many rows are in the table
$num=mysql_num_rows($result); 
mysql_close();
?>

<table border="0" cellspacing="2" cellpadding="2">
<tr>

<th>Name</th>
<th>Venue></th>
<th>Phone</th>
<th>Mobile</th>
<th>Fax</th>
<th>E-mail</th>
<th>Website</th>
<th>Address></th>
<th>City</th>
<th>State</th>
<th>Zip</th>
<th>Notes</th>
</tr>
<?php
//loop
if ($num==0) {echo"The database contains no records";}
else
{
$i=0;
while($i<$num){
$id=mysql_result($result,$i,"id");
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$venue=mysql_result($result,$i,"venue");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$website=mysql_result($result,$i,"website");
$address=mysql_result($result,$i,"address");
$city=mysql_result($result,$i,"city");
$state=mysql_result($result,$i,"state");
$zip=mysql_result($result,$i,"zip");
$notes=mysql_result($result,$i,"notes");

?>

<tr>
<td><? echo $last.", ".$first; ?></td>
<td><? echo $venue; ?></td>
<td><? echo $phone; ?></td>
<td><? echo $mobile; ?></td>
<td><? echo $fax; ?></td>
<td><a href="mailto:<? echo $email; ?>">E-mail</a></td>
<td><? echo $website; ?></td>
<td><? echo $address; ?></td>
<td><? echo $city; ?></td>
<td><? echo $state; ?></td>
<td><? echo $zip; ?></td>
<td><? echo $notes; ?></td>
<td><a href='delete.php?id=<?=$id;?>'>delete</a></td>
</tr>

<?
$i++;
}
}
echo "</table>";
?>

Link to comment
Share on other sites

try this

 

<?php
include_once("connect.php")
$id = $_GET[id];
$query = "DELETE FROM contacts WHERE id='$id'";
if (mysql_query($query))
             {
                  echo "Record deleted sucessfully";
             }
             else 
             {
                 echo "There was an error in deletion : ".mysql_error();
             }

               

Link to comment
Share on other sites

actually the code for that page should be, forgot to put the closing php tag

 

<?php
include_once("connect.php")
$id = $_GET[id];
$query = "DELETE FROM contacts WHERE id='$id'";
if (mysql_query($query))
             {
                  echo "Record deleted sucessfully";
             }
             else 
             {
                 echo "There was an error in deletion : ".mysql_error();
             }
?>

Link to comment
Share on other sites

Blank pages are usually caused by fatal parse or runtime errors. In this case the include_once() statement is missing the semi-colon ; at the end of the statement.

 

When learning, developing code, or debugging code, always check your web server log for errors and/or turn on full php error reporting in php.ini or .htaccess (fatal parse errors won't be output to the browser if you attempt to turn on error reporting in your script.)

Link to comment
Share on other sites

Thank you so much, it works now. The server will not allow me to turn on error reporting. I'm going to have to setup a testing server eventually I guess.

 

Oh, and I should probably read over when others give me a solution, I was just so anxious to make it work!

Thanks to both of you.

Now lets see if I can figure out my next issue myself :-\

 

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.