PHP - Username As Comment Message Author - Help Me Please
Hello I'm new to the forum, I need your help. I want to make a review place. but i have a problem. The name of the logged in user does not appear in the comment. can you examine the code and help me. user registration, login, done everything. this is my only problem. I tried everything, it didn't work. or I'm new. I just started. I don't know php very well.but I think I've come here so well: D <?php session_start(); include('header.php'); include_once("db_connect.php"); ?> <script src="rating.js"></script> <script type="text/javascript" src="script/ajax.js"></script> <link rel="stylesheet" href="style.css"> <?php include('container.php');?> <div class="container"> // User Register Sign Place <div class="collapse navbar-collapse" id="navbar1"> <ul class="nav navbar-nav navbar-left"> <?php if (isset($_SESSION['user_id'])) { ?> <li><p class="navbar-text"><strong>Welcome!</strong> You're signed in as <strong><?php echo $_SESSION['user_name']; ?></strong></p></li> <li><a href="logout.php">Log Out</a></li> <?php } else { ?> <li><a href="login.php">Login</a></li> <li><a href="register.php">Sign Up</a></li> <?php } ?> </ul> </div> </div> // Rating Star Place <?php include_once("db_connect.php"); $ratingDetails = "SELECT ratingNumber FROM item_rating"; $rateResult = mysqli_query($conn, $ratingDetails) or die("database error:". mysqli_error($conn)); $ratingNumber = 0; $count = 0; $fiveStarRating = 0; $fourStarRating = 0; $threeStarRating = 0; $twoStarRating = 0; $oneStarRating = 0; while($rate = mysqli_fetch_assoc($rateResult)) { $ratingNumber+= $rate['ratingNumber']; $count += 1; if($rate['ratingNumber'] == 5) { $fiveStarRating +=1; } else if($rate['ratingNumber'] == 4) { $fourStarRating +=1; } else if($rate['ratingNumber'] == 3) { $threeStarRating +=1; } else if($rate['ratingNumber'] == 2) { $twoStarRating +=1; } else if($rate['ratingNumber'] == 1) { $oneStarRating +=1; } } $average = 0; if($ratingNumber && $count) { $average = $ratingNumber/$count; } ?> <br> // Rating Details <div id="ratingDetails"> <div class="row"> <div class="col-sm-3"> <h4>Rating and Reviews</h4> <h2 class="bold padding-bottom-7"><?php printf('%.1f', $average); ?> <small>/ 5</small></h2> <?php $averageRating = round($average, 0); for ($i = 1; $i <= 5; $i++) { $ratingClass = "btn-default btn-grey"; if($i <= $averageRating) { $ratingClass = "btn-warning"; } ?> <button type="button" class="btn btn-sm <?php echo $ratingClass; ?>" aria-label="Left Align"> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> </button> <?php } ?> </div> <div class="col-sm-3"> <?php $fiveStarRatingPercent = round(($fiveStarRating/5)*100); $fiveStarRatingPercent = !empty($fiveStarRatingPercent)?$fiveStarRatingPercent.'%':'0%'; $fourStarRatingPercent = round(($fourStarRating/5)*100); $fourStarRatingPercent = !empty($fourStarRatingPercent)?$fourStarRatingPercent.'%':'0%'; $threeStarRatingPercent = round(($threeStarRating/5)*100); $threeStarRatingPercent = !empty($threeStarRatingPercent)?$threeStarRatingPercent.'%':'0%'; $twoStarRatingPercent = round(($twoStarRating/5)*100); $twoStarRatingPercent = !empty($twoStarRatingPercent)?$twoStarRatingPercent.'%':'0%'; $oneStarRatingPercent = round(($oneStarRating/5)*100); $oneStarRatingPercent = !empty($oneStarRatingPercent)?$oneStarRatingPercent.'%':'0%'; ?> <div class="pull-left"> <div class="pull-left" style="width:35px; line-height:1;"> <div style="height:9px; margin:5px 0;">5 <span class="glyphicon glyphicon-star"></span></div> </div> <div class="pull-left" style="width:180px;"> <div class="progress" style="height:9px; margin:8px 0;"> <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="5" aria-valuemin="0" aria-valuemax="5" style="width: <?php echo $fiveStarRatingPercent; ?>"> <span class="sr-only"><?php echo $fiveStarRatingPercent; ?></span> </div> </div> </div> <div class="pull-right" style="margin-left:10px;"><?php echo $fiveStarRating; ?></div> </div> <div class="pull-left"> <div class="pull-left" style="width:35px; line-height:1;"> <div style="height:9px; margin:5px 0;">4 <span class="glyphicon glyphicon-star"></span></div> </div> <div class="pull-left" style="width:180px;"> <div class="progress" style="height:9px; margin:8px 0;"> <div class="progress-bar progress-bar-primary" role="progressbar" aria-valuenow="4" aria-valuemin="0" aria-valuemax="5" style="width: <?php echo $fourStarRatingPercent; ?>"> <span class="sr-only"><?php echo $fourStarRatingPercent; ?></span> </div> </div> </div> <div class="pull-right" style="margin-left:10px;"><?php echo $fourStarRating; ?></div> </div> <div class="pull-left"> <div class="pull-left" style="width:35px; line-height:1;"> <div style="height:9px; margin:5px 0;">3 <span class="glyphicon glyphicon-star"></span></div> </div> <div class="pull-left" style="width:180px;"> <div class="progress" style="height:9px; margin:8px 0;"> <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="3" aria-valuemin="0" aria-valuemax="5" style="width: <?php echo $threeStarRatingPercent; ?>"> <span class="sr-only"><?php echo $threeStarRatingPercent; ?></span> </div> </div> </div> <div class="pull-right" style="margin-left:10px;"><?php echo $threeStarRating; ?></div> </div> <div class="pull-left"> <div class="pull-left" style="width:35px; line-height:1;"> <div style="height:9px; margin:5px 0;">2 <span class="glyphicon glyphicon-star"></span></div> </div> <div class="pull-left" style="width:180px;"> <div class="progress" style="height:9px; margin:8px 0;"> <div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="2" aria-valuemin="0" aria-valuemax="5" style="width: <?php echo $twoStarRatingPercent; ?>"> <span class="sr-only"><?php echo $twoStarRatingPercent; ?></span> </div> </div> </div> <div class="pull-right" style="margin-left:10px;"><?php echo $twoStarRating; ?></div> </div> <div class="pull-left"> <div class="pull-left" style="width:35px; line-height:1;"> <div style="height:9px; margin:5px 0;">1 <span class="glyphicon glyphicon-star"></span></div> </div> <div class="pull-left" style="width:180px;"> <div class="progress" style="height:9px; margin:8px 0;"> <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="1" aria-valuemin="0" aria-valuemax="5" style="width: <?php echo $oneStarRatingPercent; ?>"> <span class="sr-only"><?php echo $oneStarRatingPercent; ?></span> </div> </div> </div> <div class="pull-right" style="margin-left:10px;"><?php echo $oneStarRating; ?></div> </div> </div> <div class="col-sm-3"> <button type="button" id="rateProduct" class="btn btn-default">Rate this product</button> </div> </div> <div class="row"> <div class="col-sm-7"> <hr/> // Review Place <div class="review-block"> <?php $ratinguery = "SELECT ratingId, itemId, userId, ratingNumber, title, comments, created, modified FROM item_rating"; $ratingResult = mysqli_query($conn, $ratinguery) or die("database error:". mysqli_error($conn)); while($rating = mysqli_fetch_assoc($ratingResult)){ $date=date_create($rating['created']); $reviewDate = date_format($date,"M d, Y"); ?> <div class="row"> <div class="col-sm-3"> <img src="image/profile.png" class="img-rounded"> <div class="review-block-name">By <a href="#">phpcode</a></div> <div class="review-block-date"><?php echo $reviewDate; ?></div> </div> <div class="col-sm-9"> <div class="review-block-rate"> <?php for ($i = 1; $i <= 5; $i++) { $ratingClass = "btn-default btn-grey"; if($i <= $rating['ratingNumber']) { $ratingClass = "btn-warning"; } ?> <button type="button" class="btn btn-xs <?php echo $ratingClass; ?>" aria-label="Left Align"> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> </button> <?php } ?> </div> <div class="review-block-title"><?php echo $rating['title']; ?></div> <div class="review-block-description"><?php echo $rating['comments']; ?></div> </div> </div> <hr/> <?php } ?> </div> </div> </div> </div> <div id="ratingSection" style="display:none;"> <div class="row"> <div class="col-sm-12"> <form id="ratingForm" method="POST"> <div class="form-group"> <h4>Rate this product</h4> <button type="button" class="btn btn-warning btn-sm rateButton" aria-label="Left Align"> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> </button> <button type="button" class="btn btn-default btn-grey btn-sm rateButton" aria-label="Left Align"> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> </button> <button type="button" class="btn btn-default btn-grey btn-sm rateButton" aria-label="Left Align"> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> </button> <button type="button" class="btn btn-default btn-grey btn-sm rateButton" aria-label="Left Align"> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> </button> <button type="button" class="btn btn-default btn-grey btn-sm rateButton" aria-label="Left Align"> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> </button> <input type="hidden" class="form-control" id="rating" name="rating" value="1"> <input type="hidden" class="form-control" id="itemId" name="itemId" value="12345678"> </div> <div class="form-group"> <label for="usr">Title*</label> <input type="text" class="form-control" id="title" name="title" required> </div> <div class="form-group"> <label for="comment">Comment*</label> <textarea class="form-control" rows="5" id="comment" name="comment" required></textarea> </div> <?php if (isset($_SESSION['user_id'])) { ?> <div class="form-group"> <button type="submit" class="btn btn-info" id="saveReview">Save Review</button> <button type="button" class="btn btn-info" id="cancelReview">Cancel</button> </div> <?php } else { ?> <div class="well" style="margin-top: 20px;"> <h4 class="text-center"><a href="login.php">Sign in</a> to post a comment</h4> </div> <?php } ?> </form> </div> </div> </div> </div> <?php include('footer.php');?> in this line of code <div class="row"> <div class="col-sm-3"> <img src="image/profile.png" class="img-rounded"> <div class="review-block-name">By <a href="#">phpcode</a></div> <div class="review-block-date"><?php echo $reviewDate; ?></div> </div> How can I show the name of the user logging in this field? <div class="review-block-name">By <a href="#">phpcode</a></div> she will comment and her name will appear. When someone else logs in, if they comment in the same way, their name will appear. Whatever I tried did not happen. Can you help me ?
Similar Tutorials
Using Inline Php; <h1><font Color="000088">the Username <?php '.$username.' ?> Already Exists";</h1>
Im trying to create a website where users login, and then when they add a new entry to the database there name is put as the author. This is how my tables are set up. One table is named job and has the columns id, jobtext, jobdate, and authorid. Another table is called author. This table contains the columns id, username, password, and name. Authorid from the job table matches with id from the author table. When a user logins in this code is used to register the name...session_start(); $_SESSION['myusername'] = $_POST['myusername']; $_SESSION['mypassword'] = $_POST['mypassword']; header("location: index.php"); } else { echo "Wrong Username or Password"; } This is the form users use to add a new entry... if (isset($_GET['add'])) { $pagetitle = 'New Job'; $action = 'addform'; $text = ''; $authorid = ''; $id = ''; $button = 'Add job'; include $_SERVER['DOCUMENT_ROOT'] . '/jobs/includes/db.inc.php'; // Build the list of authors $sql = "SELECT id, name FROM author"; $result = mysqli_query($link, $sql); if (!$result) { $error = 'Error fetching list of authors.'; include 'error.html.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $authors[] = array('id' => $row['id'], 'name' => $row['name']); } // Build the list of categories $sql = "SELECT id, name FROM category"; $result = mysqli_query($link, $sql); if (!$result) { $error = 'Error fetching list of categories.'; include 'error.html.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $categories[] = array( 'id' => $row['id'], 'name' => $row['name'], 'selected' => FALSE); } include 'form.html.php'; exit(); } if (isset($_GET['addform'])) { include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php'; $text = mysqli_real_escape_string($link, $_POST['text']); $author = mysqli_real_escape_string($link, $_POST['author']); if ($author == '') { $error = 'You must choose an author for this job. Click ‘back’ and try again.'; include 'error.html.php'; exit(); } $sql = "INSERT INTO job SET jobtext='$text', jobdate=CURDATE(), authorid='$author'"; if (!mysqli_query($link, $sql)) { $error = 'Error adding submitted job.'; include 'error.html.php'; exit(); } $jobid = mysqli_insert_id($link); if (isset($_POST['categories'])) { foreach ($_POST['categories'] as $category) { $categoryid = mysqli_real_escape_string($link, $category); $sql = "INSERT INTO jobcategory SET jobid='$jobid', categoryid='$categoryid'"; if (!mysqli_query($link, $sql)) { $error = 'Error inserting job into selected category.'; include 'error.html.php'; exit(); } } } header('Location: .'); exit(); } Form.html.php = <?php include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/helpers.inc.php'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title><?php htmlout($pagetitle); ?></title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <style type="text/css"> textarea { display: block; width: 100%; } </style> </head> <body> <?php session_start(); ?> <h1><?php htmlout($pagetitle); ?></h1> <form action="?<?php htmlout($action); ?>" method="post"> <div> <label for="text">Type your job he </label> <textarea id="text" name="text" rows="3" cols="40"><?php htmlout($text); ?></textarea> </div> <div> <label for="author">Author:</label> <select name="author" id="author"> <option value="">Select one</option> <?php foreach ($authors as $author):?> <option value="<?php htmlout($author['id']); ?>"<?php if ($author['id'] == $authorid) echo ' selected="selected"'; ?>><?php htmlout($author['name']); ?></option> <?php endforeach; ?> </select> </div> <fieldset> <legend>Categories:</legend> <?php foreach ($categories as $category): ?> <div><label for="category<?php htmlout($category['id']); ?>"><input type="checkbox" name="categories[]" id="category<?php htmlout($category['id']); ?>" value="<?php htmlout($category['id']); ?>"<?php if ($category['selected']) { echo ' checked="checked"'; } ?>/><?php htmlout($category['name']); ?></label></div> <?php endforeach; ?> </fieldset> <div> <input type="hidden" name="id" value="<?php htmlout($id); ?>"/> <input type="submit" value="<?php htmlout($button); ?>"/> </div> </form> </body> </html> Right now, under authors, it displays all the authors in the database. I want it to just show/submit the authorid of the logged in user. CREATE TABLE posts ( postId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, title VARCHAR(255) NOT NULL, author VARCHAR(24) NOT NULL, description TEXT NOT NULL, createdAt TIMESTAMP, PRIMARY KEY (postId) ); CREATE TABLE comments( commentId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, comment TEXT NOT NULL, postId INT(11), userId INT(11), createdAt TIMESTAMP, PRIMARY KEY (commentId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (postId) REFERENCES posts(postId) ); CREATE TABLE replies ( repId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, reply TEXT NOT NULL, userId INT(11), commentId INT(11), createdAt TIMESTAMP, PRIMARY KEY (repId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (commentId) REFERENCES comments(commentId) ); CREATE TABLE users ( userId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, userName VARCHAR(100) NOT NULL,, email VARCHAR(100) NOT NULL, PRIMARY KEY (userId) ); how to retrive userName,comment, and createdAt from users and comments table while I have used userId as a Foreign key on the comment table if it isn't correct, correct me please I am pretty new to PHP and am trying to create a simple (so I assumed) page to takes data from one html page(works fine) and updates a MYSQL Database. I am getting no error message, but the connect string down to the end of the body section is showing up as plain text in my browser window. I do not know how to correct this. I have tried using two different types of connect strings and have verified my names from the HTML page are the same as listed within the php page. Suggestions on what I need to look for to correct would be great. I have looked online, but so far all I am getting is how to connect, or how to create a comment, so I thought I would try here. Thank you for any assistance I may get!! - Amy - Code: [Select] <body><font color="006600"> <div style="background-color:#f9f9dd;"> <fieldset> <h1>Asset Entry Results</h1> <?php // create short variable names $tag=$_POST['tag']; $serial=$_POST['serial']; $category=$_POST['category']; $status=$_POST['status']; $branch=$_POST['branch']; $comments=$_POST['comments']; if (!$tag || !$serial || !$category || !$status || !$branch) { echo "You have not entered all the required details.<br />" ."Please go back and try again."; exit; } if (!get_magic_quotes_gpc()) { $tag = addslashes($tag); $serial = addslashes($serial); $category = addslashes($category); $status = addslashes($status); $branch = addslashes($branch); $comments = addslashes($comments); } //@ $db = new mysqli('localhost', 'id', 'pw', 'inventory'); $db = DBI->connect("dbi:mysql:inventory:localhost","id","pw") or die("couldnt connect to database"); $query = "insert into assets values ('".$serial."', '".$tag."', '".$branch."', '".$status."', '".$category."', '".$comments."')"; $result = $db->query($query); if ($result) { echo $db->affected_rows." asset inserted into Inventory."; } else { echo "An error has occurred. The item was not added."; } $db->close(); ?> </fieldset> </div> </body> Hi, I want something this to be done. When a user tries to logged into the site by entering wrong password, the error message like " Invalid username or password" should be displayed in the same page. I tried following coding. But it shows the error message in a different page. $connect=mysql_connect('localhost','root',''); mysql_select_db('bank',$connect); $username= $_POST['username']; $password= $_POST['password']; $result = mysql_query ('select * from users where username = "' . $_POST['username'] . '" and password = "' . $_POST['password'] . '"'); while($row=mysql_fetch_row($result)){ $user_type=$row[4]; } session_start(); session_register("user_type"); $_SESSION["user_type"]=$user_type; if($user_type=='T'){ header('Location:teller_page.php'); }else if($user_type=='AO'){ header('Location:accofficer_page.php'); }else if($user_type=='AS'){ header('Location:accsup_page.php'); }else if($user_type=='LS'){ header('Location:loansup_page.php'); }else if($user_type=='CS'){ header('Location:cashsup_page.php'); }else{ header('Location:try_again.php'); } ISSUE. A User enters information into a form. If the 'username' is already taken, a 'message' in Red and with larger font-size will be returned, for example, "The username $username already exists." If the username is 'mattd' then the message should say, "The username mattd already exists." Within my php application, I have included 'inline html'. Here is part of the code: .... if (mysql_num_rows($query_run)==1) { // it will never = more than one because only //one user will or will not exist ?> <html> </body> <h1><font color="#FF0066">The username <?php echo $username; ?>already exists.</h1> </body> </html> <?php }else{ //start the registration process $query = "INSERT INTO `Names` VALUES .... 1. At one point I did get this: "The username mattd already exists." 2. But now I only get "The username already exists." I am not retrieving the $username variable. This screenshot is found he http://imgur.com/lIwLZ1G thanks. hi all, in my blog (made by me, no wordpress or similar) i would want to change the color of comments written by author of article My code is: $sql = "SELECT author WHERE art_id=..."; //print all comments... while ($row = mysql_fetch_array($result)) { if ($_SESSION['ID_user'] == $sql['ID_user'] ) { $color = "#FFFFFF"; } else { $color = "#FF0000"; } echo '<div id="comment" style="background-color: ' . $color . '">post</div>'; } but the code above print all FFFFFF or all FF0000 Where it is wrong? thanks While we're on the subject, is there a way to ensure that the first letter of a name is captalized, and the rest lowercase? Or is this best handled later on, when the name is being used and called from the DB. PS: some of us comment are code as to WHAT we are doing because we're just not that good yet, and we need to explain it to ourselves. This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=355562.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=322815.0 Code: [Select] <form name="commentbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <textarea name="comment" cols="20" rows="2" onclick="document.commentbox.comment.value='';" onfocus="this.style.borderColor='yellow';" onblur="this.style.borderColor='blue';" />Comment...</textarea> </td></tr> $commentcheck = $_POST['comment']; if ($commentcheck == "Comment...") { die(' <META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php\"> '); }else why does this not refresh if i comment "Comment..." it just dies and doesnt echo anything Okay... Since my last post about the website I was working on, I've figured out what I was asking. But now, I've run into another problem... Once I have a functional form on my website where a user inputs data and presses submit, how do I go about getting it to remain posted where directed? So if the user types his first and last name and presses submit, how do I get their input to remain posted on the page, much like a guestbook? I'm a newbie at this stuff, but it's a must for mine and my partner's website. Thanks again! PS... I have the code for the form all typed out and it works, it just displays the data with $echo rather than posting it permanantly. I dont no if this should even go here but here it goes. I created a blog were each blog post is veiwed on the same page in regards to the id passed to it (as standard). What i really need to do is incorporate the facebook comment box onto the page but... it only relates to the document itself rather than it's dynamic content. Hi everyone, I have a like button on repeating regions that is used for keeping a record of votes on comments. People click it an it adds 1 to the votes column total. It works just fine. Problem is i only want to a allow a user one vote per comment only. can vote on other comments as well, but again, only one vote per day per comment. i wouldn't know where to start. Would i use a cookie or record an ip? switch ($_REQUEST['action']) { case 'likeit'; foreach($_REQUEST as $key=>$value){ $$key = $value; } $votes = $_GET['votes']; $total = ($votes + 1); $sql = mysql_query("UPDATE quotes SET votes = '$total' WHERE quoteid = '$quoteid'"); break; } Good Afternoon everyone. I am having some problems in getting a script I found on a forum to work, I have tried contacting the original author but with no joy. Basically its a php/ajax comment system, however I am getting these errors Code: [Select] Notice: Undefined index: type in C:\wamp\www\buy2earn\viewm.php on line 93 Notice: Undefined index: type in C:\wamp\www\buy2earn\viewm.php on line 105 Here is the portion of code that I am working on, I don't understand what $_post['type'] is meant to come from? I guess its basically if the form has been submitted, but if I change the values tp 'submit' I still get the same result, just with the message submit is undefined instead! <?php $date=date("Y-m-d"); $username = $_SESSION['username']; if($_POST['type'] == "addcomment") { $username = mysql_real_escape_string($_POST['username']); $comment = mysql_real_escape_string($_POST['comment']); if($username == "" || $comment == "") { die("<p><font color='red'>Error: Please include a message.</font></p>"); } $q1 = mysql_query("INSERT INTO 'comments' ('c_id', 'm_id', 'username', 'date', 'comment') VALUES ('', '$m_id', '$username', '$date', '$comment')") or die("<p>Mysql Error: <b>".mysql_error()."</b></p>"); echo "<p><font color='green'>Comment added successfully.</font></p>"; } elseif($_POST['type'] == "getcomments") { $q1 = mysql_query("SELECT * FROM 'comments'"); $n1 = mysql_num_rows($q1); if($n1 == 0) { die("<p><font color='red'>No comments were found.</font></p>"); } echo "<table border=1>"; echo "<tr><td><b>User</b></td><td><b>Comment</b></td></tr>"; while($r1 = mysql_fetch_assoc($q1)) { $a = $r1['username']; $m = $r1['comment']; echo "<tr><td>$a</td><td>$m</td></tr>"; } echo "</table>"; } else {?> <div style="font-size: 18px;"> <p>Current Comments: </p> <div id="comments"></div> <hr /> <p>Add a comment:</p> <form action="<?php $_SERVER['PHP_SELF'];?>" method="post"> <p>Username: <input type="text" name="username" id="username" /></p> <p>Comment: <textarea name="message" cols="50" rows="10" id="message"></textarea></p> <p><input type="submit" name="submit" value="Add Comment" id="submit" /></p> </form> <div id="return"></div> </div> <?php } ?> Many Thanks for any help I have a comment form that I have created. It gets the id from the database and prints out the data that goes with that id, but what it also does is prints out the information into the form. I want a blank form so that the user can add a comment to the record. Any ideas? This the code for the form: Code: [Select] <form method="post" action="pv.php?id=<?php echo $row['ID']?>&action=<?php echo $form_action ?>"> <fieldset> <legend></legend> <p> <label for="cname">Date Of Birth</label> * <input id="cname" name="dateofbirth" class="required date" value="<?php echo $row['Date_Of_Birth']?>" /> (eg 1978.11.11) </p> <p> <label for="cgender">Gender</label> * <input type="radio" name="gender" value="Male" <?php if($row['Gender']=='male'){echo 'checked';}?>/> Male <input type="radio" name="gender" value="Female" <?php if($row['Gender']=='female'){echo 'checked';}?>/> Female </td> </p> <p> <label for="curl">Title</label> * <select name="title" id="title" class="required"> <option value="">Please Select</option> <option value="Mr" <?php if($row['Title']=='Mr'){echo 'selected';}?>>Mr</option> <option value="Ms" <?php if($row['Title']=='Ms'){echo 'selected';}?>>Ms</option> <option value="Mrs" <?php if($row['Title']=='Mrs'){echo 'selected';}?>>Mrs</option> <option value="Miss" <?php if($row['Title']=='Miss'){echo 'selected';}?>>Miss</option> <option value="Other" <?php if($row['Title']=='Other'){echo 'selected';}?>>Other</option> </select> </p> <p> <label for="ccomment">First Name</label> * <input type="text" name="firstname" value="<?php echo $row['First_Name']?>" maxlength="50" /> </p> <p> <label for="cemail">Last Name</label> * <input id="cemail" type="text" name="lastname" value="<?php echo $row['Last_Name']?>" maxlength="75" /> </p> <p> <label for="ccomment">Address 1</label>* <input type="text" name="address1" value="<?php echo $row['Address_Line_1']?>" maxlength="50" /> </p> <p> <label for="ccomment">Address 2</label> <input type="text" name="address2" value="<?php echo $row['Address_Line_2']?>" maxlength="50" /> </p> <p> <label for="ccomment">City</label>* <input type="text" name="city" value="<?php echo $row['City']?>" maxlength="50" /> </p> <p> <label for="ccomment">Postcode</label>* <input type="text" name="postcode" value="<?php echo $row['Postcode']?>" maxlength= "10" /> (eg LE5 5QE) </p> <p> <label for="ccomment">Contact No</label>* <input type="text" name="contactno" value="<?php echo $row['Contact_No']?>" maxlength= "12" /> (eg 077448825723) </p> <p> <label for="ccomment">Email</label>* <input type="text" name="email" value="<?php echo $row['Email']?>" maxlength= "40"/> (eg info@example.com) </p> <p> <label for="ccomment">Comment</label> <textarea rows="10" cols="30" name="note" maxlength= "500"><?php echo $row['Additional_Comment']?></textarea> </p> <p> <input class="submit" type="submit" value="Submit"/> </p> <p> <a href='pv.php'>Main Page</a> </p> </fieldset> This is the code for printing out the data on the page: Code: [Select] if($_GET['action']=='comment'){ $form_action = 'comment_ok'; $id=$_GET['id']; $result = mysql_query("SELECT * FROM project_data WHERE id='$id'"); $row = mysql_fetch_array($result); echo'<b>'; echo $row['Date_Of_Birth']; echo '  '; echo $row['Gender']; echo '  '; echo $row['Title']; echo '  '; echo $row['First_Name']; echo '  '; echo $row['Last_Name']; echo '  '; echo $row['Address_Line_1']; echo '  '; echo $row['Address_Line_2']; echo '  '; echo $row['City']; echo '  '; echo $row['Postcode']; echo '  '; echo $row['Contact_No']; echo '  '; echo $row['Email']; echo '  '; echo $row['Additional_Comment']; echo '</b>'; } and a snippet of the code I am using to send the id to the form: Code: [Select] echo "<td><a href='pv.php?action=edit&id=" . $row['ID']."'>Edit</a>  <a href='pv.php?action=delete_ok&id=" . $row['ID']."'>Delete</a>  <a href='pv.php?action=comment&id=" . $row['ID']."'>Comment</a></td>"; echo "</tr>"; Hi, I'm trying to improve my coding and would appreciate if someone could comment and alter my code. I dont know what would work best, named placeholders or question mark placeholders. Place the variables in a array first and then do the binding. Im looking also for solutions regarding record update using place holders. Thanks $idnrr = 1; $users = DB::getInstance()->query("SELECT * FROM users WHERE id = :id1", array(':id1' => $idnrr)); if ($users->count()) { foreach ($users->results() as $result) { echo $result->name . "<br />"; } } public function query($sql, $params) { $this->_error = false; if ($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if ($this->_query->execute($params)) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else { $this->_error = true; } } return $this; } Hi, can anyone help show me or tell me where I can find out how I can create a comment box system that will get the members userid/username and post it with the comment when it has been submitted on the page. e.g the way youtube displays comments with the username and then the comment underneath. thanks, I've got a comment box that connects to a MySQL database. I've got this error message here when I use the PHP include function to call on this script on my main page http://www.inkzoid.com/index.php ... <?php // calling session_start() the function which starts our authentication session session_start(); // connecting to mysql server $l = mysql_connect ( "999.999.999.999" , "inkzoid" , "999) or die("Error connecting:<BR><BR>".mysql_error()); mysql_select_db( "inkzoid" ) or die("Error getting db:<BR><BR>".mysql_error()); // defining getShouts() which is our function that gets all of our shouts function getShouts() { echo '<div align="center"> <table width="150" border="0" cellspacing="0" cellpadding="0"> <tr> <td> '; $query = mysql_query("SELECT * FROM shouts ORDER BY id DESC LIMIT 10") or die(mysql_error()); while ($row = mysql_fetch_array($query) ) { $name = stripslashes($row['Name']); $contact = stripslashes($row['Contact']); $shout = stripslashes($row['Shout']); if(empty($contact)) { echo '<p><span class="author">'.$name.'</span> - <span class="shout">'.$shout.'</span></p>'; } else { echo '<p><span class="author"><a href="'.$contact.'" target="_blank">'.$name.'</a></span> - <span class="shout">'.$shout.'</span></p>'; } // if empty contact } // while row mysqlfetcharray query echo '<br><br>'; echo ' </td> </tr> <tr> <td height="10"> </td> <form name="shout" method="post" action="shout.php"> <div align="center"> <input name="name" type="text" id="name" value="Name" size="25" maxlength="10"><br> <input name="contact" type="text" id="contact" value="http://" size="25"><br> <input name="message" type="text" id="message" value="Message" size="25"><br> <input name="shout" type="submit" id="shout" value="Shout!"> </div> </form> </td> </tr> </table> </div> '; } // function getshouts // our processing if control statement if ( isset ( $_POST['shout'] ) ) { $name = addslashes($_POST['name']); $contact = addslashes($_POST['contact']); $message = $_POST['message']; if ( ( isset($name) ) && ( isset($message) ) ) { // getting smilie list $smilies = mysql_query("SELECT * FROM smilies") or die(mysql_error()); while($get = mysql_fetch_array ($smilies)) { $alt = $get['Alt']; $smilie = $get['URL']; $message = str_replace( $get['Symbol'] , '<img src="smilies/'.$smilie.'" border="0" width="15" height="15" alt="'.$alt.'">' , $message); $themessage = addslashes($message); // replacing all smilies } mysql_query("INSERT INTO shouts (Name, Contact, Shout) VALUES ( '$name' , '$contact' , '$message' )") or die(mysql_error()); $_SESSION['has_posted'] = 'yes'; header("Location: shout.php"); // if required fields aren't empty, process into database } else { echo '<script>alert("Some fields were not filled out!");</script>'; header("Location: shout.php"); // if required fields were left empty, show an error dialog } }/* else { echo '<script>alert("Please follow the form to this page.");</script>'; header("Location: shout.php"); // if they weren't even referred from the form, show error dialog and redirect } // if isset post shout /* STARTING THE MAIN SCRIPT NOW */ // starting the table //displaying the shouts getShouts(); mysql_close($l); ?> I was told that I should put ob_start(); at the top of my page and ob_end_clear(); at the end of my page, but should that code go on the shout.php file or my index.php file (index.php is where I want my comment box to go)? I was using session_start(); but I got some error messsages about headers already being sent because I had originally used the php include function at the top of index.php to include shout.php. After reading up on it I found out that the error was caused by not having session_start(); being the first line of code. So my problem was that I wanted the comment box to be somewhere other than at the top of the page. Not sure how to move it. Anyways I'm pretty confused right now and if someone could give me some advice it would be appreciated. I would love to add a comment section to my music blogging site. Does anyone have some simple code that they would not mind sending me? or at least helping me with this situation? |