Deleting a record php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
edawson003
Forum Contributor
Posts: 133
Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA

Deleting a record php

Post by edawson003 »

Attempting to setup delete a record page. The below code I put together doesn't seem to work.

Code: Select all

<?
$delid=$_GET['delid'];
echo $delid;
if(isset($_POST['submit'])){
$delquery="DELETE FROM table WHERE itemid = '$delid'";
$dresult=mysql_query($delquery);
if($picturepath1 != NULL){
    unlink($picturepath);
    }
}
?>
<form method="POST" action=invlog.php?delid=$delid >
TABLE AND FORM ELEMENTS...NOT MATERIAL SO I EXCLUDED
</form>
When the delete form is initiated, the old record data is visible including the $delid; however, once I click submit I get:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/claudett/public_html/membersarea/del_exlog.php on line 21

and the reult page I include a line to echo $delid and it returns $delid (no longer includes numeric value)

I know the obvious thing would be that my mysql query syntax is off, but I think the action I set up in the <form> tag may be what I am not executing well. Any thoughts?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Deleting a record php

Post by requinix »

Code: Select all

<form method="POST" action=invlog.php?delid=$delid >
That's HTML. There aren't any variables in HTML. You told it that $_GET["delid"] is literally the value "$delid".

Code: Select all

<form method="POST" action="invlog.php?delid=<?php echo $delid; ?>">
User avatar
edawson003
Forum Contributor
Posts: 133
Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA

Re: Deleting a record php

Post by edawson003 »

Thanks for the clue. :)

I changed this:

Code: Select all

<form method="POST" action=invlog.php?delid=$delid >
to this:

Code: Select all

<form method="POST" action=invlog.php?delid=[color=#FF0000]<?[/color] $delid[color=#FF0000]; ?> [/color]>
and that got me well on my way to figuring out what else was wrong with my code. I tweaked some other bits of code and now it is working. Thanks again.
Post Reply