Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Old 08-31-2009, 10:24 AM   #1 (permalink)
Member
 
Join Date: 08-13-09
Location: Montreal
Posts: 34
iTrader: 0 / 0%
Latest Blog:
None

splap is liked by many
Exclamation MySQL help please D:

Can someone explain to me why this code:
PHP Code:
if (isset($_GET['action']))
{
    if (
$_GET['action'] == "delete")
    {
        
$sql "DELETE FROM invest WHERE 'id' = '$id' LIMIT 1";
        
$result mysql_query("DELETE FROM `invest` WHERE `invest`.`id` = 2 LIMIT 1") or die ("Invalid query: " mysql_error());
    }

Wouldn't delete the page? The connection is working fine because I can select from the table no problem. I can even delete things from other tables from this page if I want to, but I can't delete rows from the 'invest' table...
splap is offline  
Add Post to del.icio.us
Reply With Quote
Old 08-31-2009, 12:43 PM   #2 (permalink)
Contributing Member
 
Join Date: 08-30-09
Posts: 65
iTrader: 0 / 0%
warnesey333 is liked by somebodywarnesey333 is liked by somebodywarnesey333 is liked by somebody
Hm, can I ask why there is a limit?

I'm not sure whether that could be the problem, but if there were 2 records with the same ID, which would it choose to delete?

I cannot see anything different from what I normally do, try running the code in the sql section on phpmyadmin
warnesey333 is offline  
Add Post to del.icio.us
Reply With Quote
Old 08-31-2009, 01:02 PM   #3 (permalink)
Member
 
Join Date: 08-13-09
Location: Montreal
Posts: 34
iTrader: 0 / 0%
Latest Blog:
None

splap is liked by many
I put the limit because 1) there should not be two rows with the same id, that defeats the purpose and 2) because it should not delete more than one row at a time.

I've tried running the code in the SQL section from phpmyadmin and it works...
splap is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-01-2009, 10:31 AM   #4 (permalink)
Contributing Member
 
Join Date: 08-30-09
Posts: 65
iTrader: 0 / 0%
warnesey333 is liked by somebodywarnesey333 is liked by somebodywarnesey333 is liked by somebody
And the code is definitely getting into the 2 if statements?
warnesey333 is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-01-2009, 12:22 PM   #5 (permalink)
Member
 
Join Date: 08-13-09
Location: Montreal
Posts: 34
iTrader: 0 / 0%
Latest Blog:
None

splap is liked by many
well I originally set it up so that the first variable is the query, and then I just put mysql_query($query) but that didnt work so I tried it like you see it there.. no help..
splap is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-01-2009, 12:34 PM   #6 (permalink)
Junior Member
 
Join Date: 09-01-09
Posts: 6
iTrader: 0 / 0%
Latest Blog:
None

Saints is liked by many
Its currently:
Quote:
"DELETE FROM `invest` WHERE `invest`.`id` = 2 LIMIT 1"
Did you try:
Quote:
"DELETE FROM `invest` WHERE `id` = 2 LIMIT 1"
After all, if your deleting from invest, I'm presuming id would be based on the invest table in the first place, thus you do not require the additional invest before it.

And are you sure its running the query in the first place? There could be a circumstance where it bypass the if check as the condition was not met.
Saints is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-01-2009, 12:51 PM   #7 (permalink)
Member
 
Join Date: 08-13-09
Location: Montreal
Posts: 34
iTrader: 0 / 0%
Latest Blog:
None

splap is liked by many
Yes, I tried that query too.

I do think that it's not running the conditional if statement, but I don't know why.. I've tried to change the $_GET['id'] to things like letters and characters that SHOULD generate an error, but it doesn't.

Why would it not run the if statement?
splap is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-01-2009, 01:11 PM   #8 (permalink)
Contributing Member
 
Join Date: 08-30-09
Posts: 65
iTrader: 0 / 0%
warnesey333 is liked by somebodywarnesey333 is liked by somebodywarnesey333 is liked by somebody
Well it will initiate if:

The variable 'action' is set and equals "delete"

You are definitely using GET? it is not posting from a form is it and you are using POST?
warnesey333 is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-01-2009, 01:25 PM   #9 (permalink)
Member
 
Join Date: 08-13-09
Location: Montreal
Posts: 34
iTrader: 0 / 0%
Latest Blog:
None

splap is liked by many
Nope, I'm using GET. It's in the URL.

PHP Code:
<a href="investments.php?id=<? echo $row['id'?>?action=delete"><img src="images/delete.gif" alt="" /></a>
That's the link that's supposed to delete the page
splap is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-01-2009, 01:40 PM   #10 (permalink)
Junior Member
 
Join Date: 08-27-09
Posts: 3
iTrader: 0 / 0%
Latest Blog:
None

seoitc is liked by many
Code:
if ($_GET['action'] == "delete") { $result = mysql_query("DELETE FROM `invest` WHERE `invest`.`id` = 2 LIMIT 1") or die ("Invalid query: " . mysql_error()); }
try above i think this is code php code error not connection to db error or mysql error. Thanks

Last edited by htmlbasictutor; 09-01-2009 at 03:14 PM..
seoitc is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-01-2009, 02:23 PM   #11 (permalink)
Member
 
Join Date: 08-13-09
Location: Montreal
Posts: 34
iTrader: 0 / 0%
Latest Blog:
None

splap is liked by many
nope, didn't work
splap is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-03-2009, 04:50 AM   #12 (permalink)
Junior Member
 
Silverday's Avatar
 
Join Date: 09-03-09
Location: Turkey
Posts: 10
iTrader: 0 / 0%
Latest Blog:
None

Silverday is liked by many
Send a message via MSN to Silverday
PHP Code:
if (isset($_GET['action'])) 

    if (
$_GET['action'] == "delete"
    { 
        
$sql "DELETE FROM invest WHERE `id` = '$id' "
        
$result mysql_query($sql) or die ("Invalid query: " mysql_error()); 
    } 

here it's, by the way are you sure is $id set?
Silverday is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-04-2009, 10:19 AM   #13 (permalink)
Member
 
Join Date: 08-13-09
Location: Montreal
Posts: 34
iTrader: 0 / 0%
Latest Blog:
None

splap is liked by many
yes, I've tried that, and yes I'm sure $id is set
splap is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-04-2009, 10:38 AM   #14 (permalink)
Contributing Member
 
FGTH's Avatar
 
Join Date: 03-06-04
Location: NY, CT, CA, AZ
Posts: 479
iTrader: 0 / 0%
Latest Blog:
None

FGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to allFGTH is a name known to all
Check your MySQL privileges (GRANTS)... if the account you're using doesn't have DELETE privileges for the table, you won't be able to DELETE.

Code:
SHOW GRANTS FOR CURRENT_USER();
__________________
"90% of the game is half mental."
--Yogi Berra
Elizabeth Arden
FGTH is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-04-2009, 10:40 AM   #15 (permalink)
Junior Member
 
Silverday's Avatar
 
Join Date: 09-03-09
Location: Turkey
Posts: 10
iTrader: 0 / 0%
Latest Blog:
None

Silverday is liked by many
Send a message via MSN to Silverday
ohhhh! just replace this

PHP Code:
$result mysql_query($sql) or die ("Invalid query: " mysql_error()); 
PHP Code:
mysql_query($sql); 
Silverday is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-04-2009, 04:53 PM   #16 (permalink)
Member
 
Join Date: 08-13-09
Location: Montreal
Posts: 34
iTrader: 0 / 0%
Latest Blog:
None

splap is liked by many
Nope, I tried that already. Don't worry about it, I just told someone else to do it they can figure it out.

I'm almost 100% sure it was a connection problem
splap is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-05-2009, 12:09 PM   #17 (permalink)
Member
 
Join Date: 09-05-09
Posts: 36
iTrader: 0 / 0%
Latest Blog:
None

Cabloo is liked by many
Code:
if (isset($_GET['action'])) { if ($_GET['action'] == "delete") { $sql = "DELETE FROM invest WHERE 'id' = '$id' LIMIT 1"; $result = mysql_query("DELETE FROM `invest` WHERE `invest`.`id` = 2 LIMIT 1") or die ("Invalid query: " . mysql_error()); } }
Hey, try changing that to
Code:
if (isset($_GET['action'])) { if ($_GET['action'] == "delete") { $sql = "DELETE FROM invest WHERE 'id' = '$id' LIMIT 1"; echo'ATTEMPTED TO DELETE ID: ' . $id; $result = mysql_query("DELETE FROM `invest` WHERE `invest`.`id` = 2 LIMIT 1") or die ("Invalid query: " . mysql_error()); } }
That'll tell you if it's running or not.
[Removed]

Last edited by htmlbasictutor; 09-05-2009 at 10:36 PM..
Cabloo is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL RyOn Web Design Lobby 3 06-12-2009 09:38 PM
MySQL and PHP Help? birdbrain24 Coding Forum 1 02-21-2008 06:57 PM
MySQL daniel0012 Coding Forum 14 04-26-2007 02:37 PM
MYSQL gatorgritz Web Design Lobby 7 07-05-2006 11:24 PM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 07:45 PM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright © 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.