PDA

View Full Version : Trying to delete a value in a table row from MYSQL database........


Denver Jackson
07-02-2009, 08:33 AM
Hi Guys,

I'm attemping to delete a value from a certain row in my database (MYSQL). I have a delete.php file which should delete the league table's on my vBulletin forum. Here is the code I have in my delete.php file:

$leagueid = $vbulletin->input->clean_gpc('g', 'id', TYPE_UINT);



$leagueid = $db->query_write("

DELETE FROM denver_leagues

WHERE leagueid = $leagueid

");

$db->query_read("

SELECT * FROM `denver_results` WHERE 1

");

I also have the link to delete the league's which works but doesn't delete the actual league you can still see it afterwards.

Any help is appreciated.

MAORBARI
07-02-2009, 09:12 AM
$leagueid = $vbulletin->input->clean_gpc('g', 'id', TYPE_UINT);



$leagueid = $db->query_write("

DELETE FROM denver_leagues

WHERE leagueid = '$leagueid'

");

$db->query_read("

SELECT * FROM `denver_results` WHERE 1

");
enjoy.

Denver Jackson
07-02-2009, 10:22 AM
Cheers for that. Just my link now I think in the template. Here it is:

<td><if condition="$leagueid"><br /><a href="http://www.MYFORUM.com/MYFORUM/delete.php?leagueid=$leagueid">Delete</a></if>

*Myforum is just an example. That is how my link is though and it don't work like delete the league after I have entered that code above in my delete.php file.

MAORBARI
07-02-2009, 11:55 AM
the code that i bring dont work?

Denver Jackson
07-02-2009, 12:45 PM
I'm not sure don't think so.

When I type in my template for the link - <td><if condition="$leagueid"><br /><a href="http://www.MYFORUM.com/MYFORUM/delete.php?leagueid=$leagueid">Delete</a></if>

It says (EG) http://www.MYFORUM.co.uk/MYFORUM/delete.php?do=leagueid=1 on the final link before you choose to delete the league.

If I entered into the delete.php file:
$leagueid = $vbulletin->input->clean_gpc('g', 'id', TYPE_UINT);



$leagueid = $db->query_write("

DELETE FROM denver_leagues

WHERE leagueid = 1

");

$db->query_read("

SELECT * FROM `denver_results` WHERE 1

");

It would then delete league 1 when I clicked delete. This means I would have to change the code everytime the leagueid changes.

There must be a way to do this so you don't have to keep changing it.

Lynne
07-02-2009, 02:11 PM
Your cleaner statement is cleaning a GET variable called 'id', not 'leagueid'. Change one or the other. Also, it isn't really good practice to call both your variable $leagueid and your query $leagueid. And, your select statement makes no sense... WHERE 1? Where *what* is 1?

Denver Jackson
07-02-2009, 02:45 PM
I can now successfully delete the leagues with this PHP Code:

$leagueid = $vbulletin->input->clean_gpc('g', 'leagueid', TYPE_UINT);



$league = $db->query_write("

DELETE FROM denver_leagues

WHERE leagueid = 1 = $leagueid

");

$db->query_read("

SELECT * FROM `denver_results` WHERE 1

");

The only problem is I wanted a confirmation page when you click the delete button. At the moment it just appears "You have successfully deleted this league".

Lynne
07-02-2009, 03:22 PM
I don't know what you mean by confirmation page. If you want it so they have to first be told something like "You are trying to delete xxx from the database, are you sure you want to?" then you should have another do=whatever in your page to do that.

Also, this makes no sense:
WHERE leagueid = 1 = $leagueid

And, I still don't know what you think you are doing here:
SELECT * FROM `denver_results` WHERE 1

Denver Jackson
07-02-2009, 03:25 PM
It makes no sense but somehow it works. I don't know how but it just does :D

The second code I don't know what that is for but I think it makes it work.

Yes I mean they have to be first be told. In which page the delete template?

Lynne
07-02-2009, 10:14 PM
Yes I mean they have to be first be told. In which page the delete template?
You need to have a new do in that page. When they first click the link, they would click it to do=confirm and then the action for the form on that page would be do=delete