/    Sign up×
Community /Pin to ProfileBookmark

PHP Logic / Code help

Okay so here is my dilemma. I am trying to write a PHP script that is going to add and delete and edit comments.

As of now it adds comments fine. Here is the problem. When I try to delete.This is how I have my DB calls set up and stuff set up for the deletion:

$query = “MYQUERY”
$result = mysql_query($query) or die(“Unable to retrieve comments.”);
$num = mysql_numrows($result);
$i=0;
while ($i < $num)
{
$id = mysql_result($result);
$vid_id = mysql_result($result);
$comment = mysql_result($result);
$user = mysql_result($result);
$date = mysql_result($result);
$totalComments = $num;

echo ‘<b style=”color:#0DB20D;”>’,$user, ‘</b><b style=”color:#ff9002;”> – ‘,$date,’ </b>

<div class=”fixComments”>

<!— this is for deletion of comments —>

<form action=”delete” method=”GET” style=”display: inline;”>
<!– these are hidden variables that need to get passed –>
<input type=”text” name=”vidId” value=”‘, $vid_id, ‘” style=”display:none;” />
<input type=”text” name=”id” value=”‘, $id,'” style=”display:none;” />
<!– end hidden fields –>
<input type=”submit” name=”uname” value=”Delete” style=”color:#FF0000;font-size: 8pt; font-family:Calibri; cursorointer;background:transparent;border:0;”/>
</form>
</div>

So basically the logic is I was thinking I could store the vidId and Id for every one that I printed out. That way when they clicked ‘delete’ button it will be able to pull that comment from the database and show a confirm page before it deletes it.

However because every form has the same variable name, all the variables end up being set to the most recent pull from the database, so only the most recent pull can be deleted at this point.

Any ideas? Thanks.

-webDevShane

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@webDevShaneauthorJun 26.2008 — So I changed my code so every hidden input field has it's own name. But the problem still exists when I look at my source code that every value ends up getting the same value - the one of the last posted comment - so how do I fix this?

<input type="text" name="id',$i,'" value="',$id,'" style="display:none; margin:0px;">
Copy linkTweet thisAlerts:
@webDevShaneauthorJun 26.2008 — Nevermind, I found my own problem. This problem was in this statement:

$id = mysql_result($result, [COLOR="Red"]0[/COLOR], "id");

For some reason I had that set to 0, so it was always getting the very newest (or first) comment posted.

So I changed it to:

$id = mysql_result($result, [COLOR="RoyalBlue"]$i[/COLOR], "id");

And now it works flawlessly.

Thanks

-webDevShane
×

Success!

Help @webDevShane spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...