Abhi Burk Abhi Burk - 3 months ago 9
SQL Question

How do i show edit and delete buttons only for the author of the post or session user

I got one

article
table where users posted articles are stored so what i want is the article which are posted should have edit and delete button to be display to the author who has posted that or the session user only so how can i do this

Here is My Check login code

<?php
session_start();
ob_start();
require('../config.php');
//echo '<pre>'; print_r($_REQUEST); print_r($_FILES); die;

$u_ID = $_POST["u_ID"];
$dob = $_POST['dob'];

$sql = "SELECT * FROM user WHERE u_ID = '".$u_ID."' AND dob = '".$dob."'" ;
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
$count = mysql_num_rows($res);
?>

if($count != 1){
echo "Incorrect Email or Password!";
echo '<a href="../index.php">Try Again</a>';

}else {
$_SESSION['login'] =true;
$_SESSION['UID'] = $row['u_ID'];
$_SESSION['userid'] = $row['userID'];

header("location: ../student/home.php?userID=".($row['userID']));
}
?>


And What i want to display is here

$sql="SELECT * FROM article LEFT JOIN user ON
article.userID=user.userID WHERE
user.userID='".$_REQUEST['userID']."' ORDER BY articleID DESC ";
$res=mysql_query($sql);
while($row=mysql_fetch_assoc($res)){

if(($_SESSION["login"])) { ?>

<i class="glyphicon glyphicon-pencil"></i><a href="editArticle.php?xAction=edit$articleID=<?php echo $row['articleID'];?>"> Edit </a>
<i class="glyphicon glyphicon-trash"></i>a href="delArticle.php?xAction=del$articleID=<?php echo $row['articleID'];?>">Delete</a>




just want basic format for above mentioned code as i m new to php i cant explain much about the code

Answer

Look its simple.. try something like this see the field names please

$sql="SELECT * FROM article LEFT JOIN user ON   
         article.userID=user.userID WHERE
         user.userID='".$_REQUEST['userID']."' ORDER BY articleID DESC ";
$res=mysql_query($sql);
while($row=mysql_fetch_assoc($res)){     
        if(($_SESSION["login"]) && $_SESSION['UID'] == $row['userID']) { ?>
            <i class="glyphicon glyphicon-pencil"></i><a href="editArticle.php?xAction=edit$articleID=<?php echo $row['articleID'];?>"> Edit </a>
          <i class="glyphicon glyphicon-trash"></i>a href="delArticle.php?xAction=del$articleID=<?php echo $row['articleID'];?>">Delete</a>