Jump to content

Mysql delete


paulman888888

Recommended Posts

Please can you check the code.

I always do something wrong but never spot it.

<?php
mysql_query("DELETE FROM example WHERE id=$_GET[id]");
?>

 

Thankyou

 

Do you get any errors? If so, then what? Without that info, I'd say check to make sure your table and column is spelled right (and exist). 

 

Is that the full extent of your code? Because if it is, then you need to connect to your database first...

Link to comment
Share on other sites

try :

 

 

$sql = mysql_query("DELETE FROM example WHERE id=$_GET[id]");
$result = mysql_query($sql);

 

No

 

Oh how come? This is the code i use to delete a record and works for me.

 


$id = (int)$_POST['id']; 

				$sql="DELETE FROM `tablw` WHERE `id`={$id} "; 
				$result = mysql_query($sql); 

Link to comment
Share on other sites

There are security implications with the way in which you are trying to do your delete, but those have been mentioned and I'm going to assume that you'll be dealing with them.

<?php
  $sql ="DELETE FROM example WHERE id=$_GET[id]";
  $result = mysql_query($sql);
?>

 

Would become

 

<?php
  $sql="DELETE FROM example WHERE id={$_GET['id']};";
  $result=mysql_query($sql);
?>

 

Please note the curly braces around $_GET['id']. These tell the php parser that this is a variable inside this string. A better approach might be this (depending on which you prefer to look at, although both will have the same result).

 

<?php
  $sql="delete from example where id=".$_GET['id'].";";
?> 

Link to comment
Share on other sites

there is nothing syntactically wrong with any of the suggestions...or the OP's posted code.  So the only thing we can really do is ask him what he means by "it's not working."  Is it insecure? Yes, but that's not the question (unless "it's not working" means it works, but it's not secure, but again, he needs to explain). 

 

At face value, all I can say at this point in time is that what he initially posted is in fact his entire code, in which case, I would ask him about connecting to the database first. 

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.