Jump to content


Photo

Problem trying to edit


  • Please log in to reply
1 reply to this topic

#1 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 02 August 2006 - 06:09 PM

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)

<?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>";
} 
?>

edit script

<?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>

<?

}

}

?>

well i think the idea is get each id of the post so select from replies is wrong im thinking.
Dont Piss me Off today

#2 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 02 August 2006 - 06:59 PM

Your question is somewhat ambiguous. 

you have -

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


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:
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">

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users