Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 15th, 2005, 10:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: South Bend, Indiana, USA.
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default Delete query not working

I am trying to fix my delete function that deletes a string of text that may or may not have single, double quotes, pound signs etc.


Code:
function delete_bm($user, $url)
{
  // delete one text string from the database NOT a url as would be suggested
  if (!($conn = db_connect()))
    return false;

   // delete the Item
  if (!mysql_query( "delete from XMAS_WISH_LIST
                       where username='$user' and XMAS_ITEM='".mysql_escape_string($url)."'"))
    return false;
  return true;  
}
When I run this on my web page, I don't get an error, it just does not delete the item that I am passing it, like the following: "test" (with quotes).

Any suggestions?


Mitch
__________________
Mitch
 
Old November 16th, 2005, 08:09 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Do you have magic_quotes_gpc activated? If so you don't need mysql_escape_string().

If not, try more aggressive error reporting.

Output the query, so you can see if there is something erroneous.
Code:
echo "delete from XMAS_WISH_LIST
                       where username='$user' and XMAS_ITEM='".mysql_escape_string($url)."'";
And output any mysql errors.

Code:
$query = mysql_query(
    "DELETE
       FROM XMAS_WISH_LIST
      WHERE username  = '$user' 
        AND XMAS_ITEM = '".mysql_escape_string($url)."'"
);

if (!$query)
{
    echo mysql_errno().': '.mysql_error()."\n";
    return false;
}
else
{
    return true;
}
HTH!


Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old November 17th, 2005, 03:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: South Bend, Indiana, USA.
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It looks like when I click on the "submit" button it is sending everything up to the quote, so I am not sure what to do to correct that.

Mitch
 
Old December 30th, 2005, 08:02 AM
Registered User
 
Join Date: Dec 2005
Location: Pretoria, Gauteng, South Africa.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Christoff Send a message via Yahoo to Christoff
Default

Did you check your variable scope?

If $conn is the connection you use, you must set which $conn you're going to use, the one in the current function, or a globally defined one?


function delete_bm($user, $url)
{
global $conn;
etc etc etc...


 
Old January 4th, 2006, 08:00 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

May be, user that is connected to MySQL database via PHP script may not have delete permission ..!

`~@#\^%&*/\.<.\/-|+|_!:;..=?>
Students' finances




Similar Threads
Thread Thread Starter Forum Replies Last Post
php/mysql delete button and delete query dungey PHP Databases 17 April 11th, 2009 12:24 PM
Delete Button not working in Wrox CMS VB Sojan80 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 June 16th, 2007 03:23 AM
delete is not working thas123 ADO.NET 1 January 6th, 2006 09:41 AM
Delete Query not working kbonney98 Access 1 April 14th, 2005 06:29 AM
Edit/Delete ButtonColumn not working planoie ASP.NET 1.0 and 1.1 Professional 9 August 30th, 2004 07:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.