Jump to content

Delete Database Entry Code... Help!


mat3000000

Recommended Posts

No errors come up when I run this but it just doesn't delete the entry.

 

 

<?
$rec = $_POST['stock'];
if (!$rec){ 
die ('Please eneter a stock number');
}

$link = mysql_connect("xxxx","xxx","xxx");
mysql_select_db('wadkin', $link) or die( "Unable to select database");

mysql_query("DELETE FROM 'wadkin'.'stocklist' WHERE 'stocklist'.'Stock Number' = $rec")
or die ('Query failed');

mysql_close($link);

?>

 

Can someone please correct,

 

(btw I have also tried... "DELETE FROM stocklist WHERE 'Stock Number' = $rec")

Link to comment
Share on other sites

<?php

error_reporting(E_ALL);

$link = mysql_connect("xxxx","xxx","xxx");
mysql_select_db('wadkin', $link) or die( "Unable to select database");

//'Catch' the $_POST value being submitted
if (isset($_POST['stock']) && !empty($_POST['stock'])){

$rec = strip_tags(mysql_real_escape_string($_POST['stock']));//sanitise first

//issue the query
$res = mysql_query("DELETE FROM `wadkin`.`stocklist` WHERE `stocklist`.`Stock Number` = ".$rec." ") or die ('Query failed'.mysql_error());

//Check that the query was successful
if($res){
	echo "record deleted!";
	exit;
}
else{
	echo "Uh-oh, something went wrong!";
	exit;
}

}
else{
echo "Please enter a valid stock number!";
exit;
}
?>

 

There are better ways, but this will work fine for what you are trying to achieve.

 

If the 'stock' value isn't numerical, you will need to quote ('".$rec."') that value in the sql.

 

Rw

Link to comment
Share on other sites

I am now given an error:

 

Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\admin\delete.php on line 10

 

Line 10 is:

$res = mysql_query($link, "DELETE FROM 'stocklist' WHERE 'Stock Number'=".$rec."")

 

???????

 

Please can someone correct.

Thanks

Link to comment
Share on other sites

Keep forgetting back-sticks not quotes! :S oops!

 

You'll all be glad to know I got this...

 

Unknown column 'S8637' in 'where clause'

 

What does this mean in english please?

If it means it can't find this entry in the table under `Stock Number` then something has gone wrong, I know that this number is in my table????

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.