 |
| Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more. |
|
 |
08-31-2009, 10:24 AM
|
#1 (permalink)
|
|
Member
Join Date: 08-13-09
Location: Montreal
Posts: 34
Latest Blog: None
|
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...
|
|
|
08-31-2009, 12:43 PM
|
#2 (permalink)
|
|
Contributing Member
Join Date: 08-30-09
Posts: 65
|
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
|
|
|
08-31-2009, 01:02 PM
|
#3 (permalink)
|
|
Member
Join Date: 08-13-09
Location: Montreal
Posts: 34
Latest Blog: None
|
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...
|
|
|
09-01-2009, 10:31 AM
|
#4 (permalink)
|
|
Contributing Member
Join Date: 08-30-09
Posts: 65
|
And the code is definitely getting into the 2 if statements?
|
|
|
09-01-2009, 12:22 PM
|
#5 (permalink)
|
|
Member
Join Date: 08-13-09
Location: Montreal
Posts: 34
Latest Blog: None
|
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..
|
|
|
09-01-2009, 12:34 PM
|
#6 (permalink)
|
|
Junior Member
Join Date: 09-01-09
Posts: 6
Latest Blog: None
|
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.
|
|
|
09-01-2009, 12:51 PM
|
#7 (permalink)
|
|
Member
Join Date: 08-13-09
Location: Montreal
Posts: 34
Latest Blog: None
|
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?
|
|
|
09-01-2009, 01:11 PM
|
#8 (permalink)
|
|
Contributing Member
Join Date: 08-30-09
Posts: 65
|
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?
|
|
|
09-01-2009, 01:25 PM
|
#9 (permalink)
|
|
Member
Join Date: 08-13-09
Location: Montreal
Posts: 34
Latest Blog: None
|
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
|
|
|
09-01-2009, 01:40 PM
|
#10 (permalink)
|
|
Junior Member
Join Date: 08-27-09
Posts: 3
Latest Blog: None
|
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..
|
|
|
09-01-2009, 02:23 PM
|
#11 (permalink)
|
|
Member
Join Date: 08-13-09
Location: Montreal
Posts: 34
Latest Blog: None
|
nope, didn't work
|
|
|
09-03-2009, 04:50 AM
|
#12 (permalink)
|
|
Junior Member
Join Date: 09-03-09
Location: Turkey
Posts: 10
Latest Blog: None
|
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?
|
|
|
09-04-2009, 10:19 AM
|
#13 (permalink)
|
|
Member
Join Date: 08-13-09
Location: Montreal
Posts: 34
Latest Blog: None
|
yes, I've tried that, and yes I'm sure $id is set
|
|
|
09-04-2009, 10:38 AM
|
#14 (permalink)
|
|
Contributing Member
Join Date: 03-06-04
Location: NY, CT, CA, AZ
Posts: 479
Latest Blog: None
|
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
|
|
|
09-04-2009, 10:40 AM
|
#15 (permalink)
|
|
Junior Member
Join Date: 09-03-09
Location: Turkey
Posts: 10
Latest Blog: None
|
ohhhh! just replace this
PHP Code:
$result = mysql_query($sql) or die ("Invalid query: " . mysql_error());
|
|
|
09-04-2009, 04:53 PM
|
#16 (permalink)
|
|
Member
Join Date: 08-13-09
Location: Montreal
Posts: 34
Latest Blog: None
|
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
|
|
|
09-05-2009, 12:09 PM
|
#17 (permalink)
|
|
Member
Join Date: 09-05-09
Posts: 36
Latest Blog: None
|
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..
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
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 |
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.
|
|
|