Jump to content

Archived

This topic is now archived and is closed to further replies.

scheols

Problem trying to edit

Recommended Posts

alright see i have this script that edits post but problem is when i try and edit others besides the second post it doesnt edit it only grabs the first post so how can i get each post in each topic by thier post id?

addpost.php script part(just the php script for edit)
[quote][code=php:0]
<?php
if($logged[level] != 5 && $logged[level] != 3 && $logged[level] != 4){
echo "";
} else {
echo "<a href='fpedit.php?id=$s'>Edit</a>";
} if($logged[level] ==1 && $logged[username] == $t[username]){
echo "<a href='fpedit.php?id=$s'>Edit</a>";
}
?>
[/code] [/quote]
edit script[quote]
[code=php:0]
<?php

include "config.php";

$zid = $_GET['id'];

$submit = $_POST['esubmit'];

$p_zid = $_POST['zid'];

if($submit){
if($logged[username] ==null){
echo "You not allowed to edit";
exit;
}

$ename = $_POST['ename'];

$epost = $_POST['epost'];



mysql_query("UPDATE `replies` SET `post` = '$epost', `username` = '$ename' WHERE `tid` = '$p_zid' ");

echo "Thank You Your News Has Been Edited SuccessfullyYou Will Now Be Redirected <meta http-equiv=Refresh content=4;url=index.php>";

}

elseif(!isset($submit)){



$result = mysql_query("SELECT * FROM replies WHERE id='$zid' ORDER BY id ASC");

while($row = mysql_fetch_array($result)){



$name = $row['username'];

$post = $row['post'];

?>



<h2>::Edit Posts::</h2>



<form method="post" action="<?php echo $PHP_SELF ?>">

<input type="hidden" name="zid" value="<? echo $zid; ?>">

Name: <input type="text" name="ename" maxlength="20" value="<? echo $name; ?>"><br>

Post:<textarea name="epost"><? echo $post; ?></textarea>

<input type="submit" name="esubmit" value="Update Post">

</form>

<?

}

}

?>
[/code]
[/quote]
well i think the idea is get each id of the post so select from replies is wrong im thinking.

Share this post


Link to post
Share on other sites
Your question is somewhat ambiguous. 

you have -

[quote]$result = mysql_query("SELECT * FROM replies WHERE id='$zid' ORDER BY id ASC");
[/quote]

indicating that for each id, there are multiple results.  Yet for each form generated for each record, you UPDATE the database for the same id.  It seems to me if for one id you have ten different username/post pairs, and then you submit one of the forms and run your UPDATE query, that you will overwrite the ten existing records to the same value.


lets say you have for each id multiple username/post pairs in your database.  To maintain the multiple unique records for each id, you will need to create another id that identifies each unique pair.  So your db will look like such-

user_id      post_id    username      post

you then use post_id, the unique id for each username/post pair to name your form input elements:
[code]
elseif(!isset($submit)){


$result = mysql_query("SELECT * FROM replies WHERE user_id='$zid' ORDER BY id ASC");

while($row = mysql_fetch_array($result)){


$post_id=$row['post_id'];

$name = $row['username'];

$post = $row['post'];

?>

<h2>::Edit Posts::</h2>

<form method="post" action="<?php echo $PHP_SELF ?>">

Name: <input type="text" name="ename_<?PHP echo $post_id;?>" maxlength="20" value="<? echo $name; ?>"><br>

Post:<textarea name="epost_<?PHP echo $post_id;?>"><? echo $post; ?></textarea>


</form>

<?

}

<input type="submit" name="submit" value="Update Posts">
[/code]

then when you get your post variables, you can use the string functions on the keys to find the username/post pairs and create your database UPDATE queries.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.