Jump to content


Photo

remember a member (need a guru)


  • Please log in to reply
9 replies to this topic

#1 ittech

ittech
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 August 2006 - 09:37 AM

Hi,

i made a member system got some of it from phpfreaks and it works great  ;D but i want to make a posting area for my members. i seen the simple forum script of here so i got some thing like that in mind. I just don't know how to allow my members to edit or delete a post. i know how to delete posts and edit them if you know what i mean it's just allowing the person who submits the post to edit or delete it??????

it would be really great if someone could show me as well as tell me how this could be done.

Thanks

#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 17 August 2006 - 11:26 AM

All you have to do is make sure you store the member that created the post along with the post contents/title/date etc.

Then, when you display the post, check to see if the current user is the same as the user who created the post. If it is then show them links to delete or edit the post.

I hope that is what you were asking.

#3 ittech

ittech
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 August 2006 - 12:26 PM

yes thats what i want to do

but i don't know how to code that? ??? my script logs there userid when they post and only lets members see the submit post box. Am 5 weeks old to php and most the stuff i have done i learned from phpfreaks.

thanks for the reply i hope you reply back to this  ;D

#4 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 17 August 2006 - 12:28 PM

are you storing these posts in a database or in a static file ..i.e. a html file?

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#5 ittech

ittech
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 August 2006 - 12:32 PM

i use a mysql database  ;) please help me out codingforums can't seem to help me so am hoping there are professionals on this help forum  ;D

<? 
include("include/session.php"); 
?> 

<html> 
<title>simple</title> 
<body> 

<table> 
<tr><td> 


<? 
if($session->logged_in){ 
   echo "<h1>Logged In</h1>"; 
   echo "Welcome <b>$session->username</b>, you are logged in. <br><br>" 
       ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;" 
       ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;"; 
   if($session->isAdmin()){ 
      echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;"; 
   } 
   echo "[<a href=\"process.php\">Logout</a>]"; 
} 
else{ 
?> 

<h1>Login</h1> 
<? 
if($form->num_errors > 0){ 
   echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>"; 
} 
?> 
<form action="process.php" method="POST"> 
<table align="left" border="0" cellspacing="0" cellpadding="3"> 
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr> 
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr> 
<tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>> 
<font size="2">Remember me next time &nbsp;&nbsp;&nbsp;&nbsp; 
<input type="hidden" name="sublogin" value="1"> 
<input type="submit" value="Login"></td></tr> 
<tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr> 
<tr><td colspan="2" align="left"><br>Not registered? <a href="register.php">Sign-Up!</a></td></tr> 
</table> 
</form> 

<? 
} 
echo "</td></tr><tr><td align=\"center\"><br><br>"; 
echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>"; 
echo "There are $database->num_active_users registered members and "; 
echo "$database->num_active_guests guests viewing the site.<br><br>"; 
include("include/view_active.php"); 
?> 


</td></tr> 
</table> 


</body> 
</html> 

<? 
include("include/dbcon.php"); 
?> 
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> 
<tr> 
<td width="6%" align="center" bgcolor="#E6E6E6"><strong>#</strong></td> 
<td width="53%" align="center" bgcolor="#E6E6E6"><strong>Topic</strong></td> 
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Views</strong></td> 
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Replies</strong></td> 
<td width="13%" align="center" bgcolor="#E6E6E6"><strong>Date/Time</strong></td> 
</tr> 

<?php 
while($rows=mysql_fetch_array($result)){ // Start looping table row  
?> 
<tr> 
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> 
<td bgcolor="#FFFFFF"><a href="view_topic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td> 
<td align="center" bgcolor="#FFFFFF"><? echo $rows['view']; ?></td> 
<td align="center" bgcolor="#FFFFFF"><? echo $rows['reply']; ?></td> 
<td align="center" bgcolor="#FFFFFF"><? echo $rows['datetime']; ?></td> 
</tr> 

<?php 
// Exit looping and close connection  
} 
mysql_close(); 
?> 
<tr> 
<td colspan="5" align="right" bgcolor="#E6E6E6"><a href="./create_topic.php"><strong>Create New Topic</strong> </a></td> 
</tr> 
</table> 

VIEW_TOPIC.php
<? 
include("include/session.php"); 
?> 
<h1>User: <? echo $session->username; ?></h1> 

<?php 
$host="localhost";  
$username="****";   
$password="****";  
$db_name="****";   
$tbl_name="****";  


mysql_connect("$host", "$username", "$password")or die("cannot connect");  
mysql_select_db("$db_name")or die("cannot select DB"); 


$id=$_GET['id']; 

$sql="SELECT * FROM $tbl_name WHERE id='$id'"; 
$result=mysql_query($sql); 

$rows=mysql_fetch_array($result); 
?> 

<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> 
<tr> 
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF"> 
<tr> 
<td bgcolor="#F8F7F1"><strong><? echo $rows['topic']; ?></strong></td> 
</tr> 

<tr> 
<td bgcolor="#F8F7F1"><? echo $rows['detail']; ?></td> 
</tr> 

<tr> 
<td bgcolor="#F8F7F1"><strong>By :</strong> <? echo $rows['name']; ?> <strong>Email : </strong><? echo $rows['email'];?></td> 
</tr> 

<tr> 
<td bgcolor="#F8F7F1"><strong>Date/time : </strong><? echo $rows['datetime']; ?></td> 
</tr> 
</table></td> 
</tr> 
</table> 
<BR> 
<?php 
$tbl_name2="forum_answer"; // Switch to table "forum_answer"  

$sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id'"; 
$result2=mysql_query($sql2); 

while($rows=mysql_fetch_array($result2)){ 
?> 
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> 
<tr> 
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> 
<tr> 
<td bgcolor="#F8F7F1"><strong>ID</strong></td> 
<td bgcolor="#F8F7F1">:</td> 
<td bgcolor="#F8F7F1"><? echo $rows['a_id']; ?></td> 
</tr> 
<tr> 
<td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td> 
<td width="5%" bgcolor="#F8F7F1">:</td> 
<td width="77%" bgcolor="#F8F7F1"><? echo $rows['a_name']; ?></td> 
</tr> 
<tr> 
<td bgcolor="#F8F7F1"><strong>Email</strong></td> 
<td bgcolor="#F8F7F1">:</td> 
<td bgcolor="#F8F7F1"><? echo $rows['a_email']; ?></td> 
</tr> 
<tr> 
<td bgcolor="#F8F7F1"><strong>Answer</strong></td> 
<td bgcolor="#F8F7F1">:</td> 
<td bgcolor="#F8F7F1"><? echo $rows['a_answer']; ?></td> 
</tr> 
<tr> 
<td bgcolor="#F8F7F1"><strong>Date/Time</strong></td> 
<td bgcolor="#F8F7F1">:</td> 
<td bgcolor="#F8F7F1"><? echo $rows['a_datetime']; ?></td> 
</tr> 
</table></td> 
</tr> 
</table><br> 

<? 
} 

$sql3="SELECT view FROM $tbl_name WHERE id='$id'"; 
$result3=mysql_query($sql3); 

$rows=mysql_fetch_array($result3); 
$view=$rows['view']; 

// if have no counter value set counter = 1 
if(empty($view)){ 
$view=1; 
$sql4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'"; 
$result4=mysql_query($sql4); 
} 

// count more value 
$addview=$view+1; 
$sql5="update $tbl_name set view='$addview' WHERE id='$id'"; 
$result5=mysql_query($sql5); 

mysql_close(); 
?> 
<BR> 
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> 
<tr> 
<form name="form1" method="post" action="add_answer.php"> 
<td> 
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> 
<tr> 
<td width="18%"><strong>Name</strong></td> 
<td width="3%">:</td> 
<td width="79%"><input name="a_name" type="text" id="a_name" size="45"></td> 
</tr> 
<tr> 
<td><strong>Email</strong></td> 
<td>:</td> 
<td><input name="a_email" type="text" id="a_email" size="45"></td> 
</tr> 
<tr> 
<td valign="top"><strong>Answer</strong></td> 
<td valign="top">:</td> 
<td><textarea name="a_answer" cols="45" rows="3" id="a_answer"></textarea></td> 
</tr> 
<tr> 
<td>&nbsp;</td> 
<td><input name="id" type="hidden" value="<? echo $id; ?>"></td> 
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td> 
</tr> 
</table> 
</td> 
</form> 
</tr> 
</table> 


#6 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 17 August 2006 - 02:14 PM

I didnt look over your entire code but what you want to try and do when someone tries to delete something.. try something like:

pseudo:
<?php

$user_id = $MEMBERID;    // The ID of the poster who posted the... post :P
$post_id = $POSTID;       // The ID of the actual post itself.
$strqry = "DELETE FROM posts WHERE post_id = '{$post_id}' AND poster_id = '{$user_id}' LIMIT 1";

$query = mysql_query($strqry) or die("MySQL Error: <br />{$strqry}<br />". mysql_error());
$num = mysql_affected_rows($query);

if($num > 0) {
   // Post was deleted successfully;
   echo "You have deleted the post";
} else {
   echo "The post was not delete succesfully";
}
?>

Now I would put in slightly better check to see if the user is even allowed to delete the post in the first place. I would have  a check when you show the posts that if the user looking at the post, is their own post, then I would display them a 'delete' link.  Otherwise they wont get one at all.  Then the SQL query would check to make sure that if the person trying to delete the post, was indeed the person who originally posted it and if so, delete it from the database.

Whew.. Hope that helps a little bit :)

#7 ittech

ittech
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 August 2006 - 03:09 PM

My point to the post was to find out a way for my script to let the person who submitted the post delete it or edit it by adding in a button after it has check the post belongs to that user (am not sure how to check the post to the user).

But you have helped more then those at codingforum thanks a lot.

still confused.com  ???

#8 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 17 August 2006 - 03:12 PM

<?php

if ($session->userid == $user_id_from_post) {
  // show buttons
}

?>

to get you started.

#9 ittech

ittech
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 18 August 2006 - 08:41 AM

<?php

if ($session->userid == $user_id_from_post) {
  // show buttons
}

?>

to get you started.


that's great someone helpped me. But how come when i login the echo goes and when i log out it shows? It should be the other way around? Any ideas?

#10 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 18 August 2006 - 11:28 PM

Can you post that bit of code? 




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users