
aleX2
Members-
Posts
21 -
Joined
-
Last visited
aleX2's Achievements

Member (2/5)
0
Reputation
-
It's done... Table: users user_id int(11) firstname varchar(100) email varchar(50) password varchar(300) status enum('admin','user') Table: comment comment_id int(11) user_id int(11) news_id int(11) firstname varchar(50) comment text time timestamp Table: news news_id int(11) title varchar(200) text text category varchar(20) time timestamp author varchar(50)
-
Diff between name(is for first and lastname) and username{nickname). For text fields they told us to put text and not varchar.So we don't have to worry about word limit. Thanks for suggestion, it is a good one. In school they told us to use timestamp. As I told you I am a begginer and I don't know a lots of things. That is why I came here in first place.
-
Table: comment comment_id int(11) user_id int(11) news_id int(11) name varchar(50) comment text time timestamp Table: users user_id int(11) name varchar(100) email varchar(50) username varchar(50) password varchar(300) status enum('admin','user') Table: news news_id int(11) title varchar(200) text text category varchar(20) time timestamp author varchar(50)
-
They told me to expand so i can see what user on what news left the comment. It is a "newspaper" folder in mysql so I have: users table id, name, email, password, status comment table I have id, user_id, newsid, name, comment and time news table id, title, text, category, author Point is to show news and only logged in user can comment on that news.User can only delete the message that he wrote and admin can delete all messages.
-
They told me to do this: "Only logged in users need to be able to write comments. It is necessary to keep the user id in the session. Expand the comment table with the user_id column to keep track of which user left the comment (you are taking the user id from the session). When scrolling through comments, it is necessary to compare whether the user id and the comment table match the user id from the session, if it matches, only then display the delete buttons." Well, I done the part that only logged in users are able to write a comment and I expanded table...But when it comes to write a match code I get lost.Or I don't write a code well or I don't put it in the right place.I don't know where is the problem.😰
-
<?php session_start(); require_once("function.php"); require_once("class/DataB.class.php"); $conn = new DataB(); if(!$conn->connect()) { echo "Wrong DB connection!"; exit(); } if(isset($_POST['comment'])){ if(login()) { $id = $_SESSION['id']; $user_id = $_SESSION['user_id']; $status = $_SESSION['status']; } $query = "DELETE FROM comment WHERE user_id={$id}"; $conn->query($query); header("Location: deletecomment.php"); } ?> And this is a dcomm page
-
<?php session_start(); require_once("function.php"); require_once("class/DataB.class.php"); $conn = new DataB(); if(!$conn->connect()) { echo "Wrong DB connection!"; exit(); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Delete Comment</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <div id="container"> <?php require_once("nav.php"); if(login()) { $id = $_SESSION['id']; $query = "SELECT * FROM comment"; } $res = $conn->query($query); if($conn->num_rows($res) > 0){ while($row = $conn->fetch_assoc($res)){ ?> <div id="img"> <a href="dcomm.php?id=<?php echo $row['id'];?>"><img src="img/delete.png" title="DELETE COMMENT"></a> <p><b> Name: </b><br><?php echo $row['name'];?></p> <p><b> Comment: </b><br><?php echo $row['comment'];?></p> </div> <hr> <?php } }else{ echo "<h3>No comments!</h3>"; } ?> </div> </div> </body> this is delecomment page