PHP - Adding A Comment Section
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?
Similar Tutorialshi i have got the following issues i am using the following code. Code: [Select] <?php //DB CONNECTION $ROWS = "id,firstname,lastname"; // explode at the comma and insert into an array $test = explode("," , $ROWS); //adds array test to the var sam $sam = array($test); // querys the database $new = mysql_query("SELECT * FROM {$DB_TABLE}"); // while loop to loop through selected fields while ($row = mysql_fetch_array($new)) { foreach ($sam[0] as $v) { echo $row[$v] . $DELIMITER . "<br />"; } } ?> i get the following results. 834(|) Steph(|) Thompson(|) 835(|) Lucy(|) kim(|) 836(|) Iwan(|) Will(|) 837(|) Sarah (|) Good(|) The problem i have is the br tag where do i put it because i need it to output like this. like it shows in the $ROWS variable above "$ROWS = "id,firstname,lastname";"; 834(|)Step(|)Thompson(|) 835(|)Lucy(|)kim(|) 836(|)Iwan(|)Will(|) 837(|)Sarah (|)Good(|) Where do i add the br tag??? Any Help PLease I have a checkout form that goes like this... Code: [Select] <?php session_start(); ?> <!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"> <head></head> <body></body> </html> Can I start adding this line of code to all of my PHP files - AS THE LAST LINE - without any negative consequences?? Code: [Select] <? // Build date 2011-05-14 ?> Debbie hope someone can help me out here, stuck on this page... This page shows the details of the listing they had just clicked on on the previous page. this part works If the person logged in is the person who is looking at the page, the email section does not show. this part works However, the part I cannot get to work, is when the logged in user types their email message and clicks send email. at this point the details of listing stop showing please SOMEONE HELP ME thanks in advance, i hope Code: [Select] <?php // Start the session require_once('startsession.php'); // Insert the page header $page_title = 'Listing Details'; require_once('header.php'); require_once('connectvars.php'); // Show the navigation menu require_once('navmenu.php'); if(isset($_POST['submit'])){ $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the user data from MySQL $query1 = 'SELECT email FROM ob_user WHERE username="' . $user_name . '"'; $data1 = mysqli_query($dbc, $query1); $row1 = mysqli_fetch_array($data1); $email = $row1['email']; $to = $email; $subject = 'OurBazzar response to' . $subject . ''; $body = $_POST['email']; $headers = 'From: caleb.jordan.flax@gmail.com'; if (mail($to, $subject, $body, $headers)) { echo("<p>Message sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } end(); } if (isset($_GET['listing_id']) && isset($_GET['subject']) && isset($_GET['description']) && isset($_GET['price']) && isset($_GET['date']) && isset($_GET['city']) && isset($_GET['state']) && isset($_GET['user_id']) && isset($_GET['category_id'])) { // Grab the score data from the GET $listing_id = $_GET['listing_id']; $title = $_GET['subject']; $description = $_GET['description']; $price = $_GET['price']; $date = $_GET['date']; $city = $_GET['city']; $state = $_GET['state']; $userid = $_GET['user_id']; $categoryid = $_GET['category_id']; } // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the user data from MySQL $query = 'SELECT username FROM ob_user WHERE user_id="' . $userid . '"'; $data = mysqli_query($dbc, $query); $row = mysqli_fetch_array($data); $query1 = 'SELECT name FROM ob_category WHERE category_id="' . $categoryid . '"'; $data1 = mysqli_query($dbc, $query1); $row1 = mysqli_fetch_array($data1); $user_name = $row['username']; $category_name = $row1['name']; echo '<table>'; echo '<tr><td colspan="2"><strong>' . $title . '</strong></td></tr>'; echo '<tr><td>Created by: </td><td>' . $user_name . '</td></tr>'; echo '<tr><td>Date created: </td><td>' . $date . '</td></tr>'; echo '<tr><td>Location: </td><td>' . $city . ', ' . $state . '</td></tr>'; echo '<tr><td>Category: </td><td>' . $category_name . '</td></tr>'; echo '<tr><td>Description: </td><td>' . $description . '</td></tr>'; echo '</table>'; if ((isset($_SESSION['username'])) && ($_SESSION['username'] != $user_name)) { ?> <br /> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Send Email to <?php echo $user_name; ?></legend> <label for="email">Message: </label> <input type="text" name="email" /><br /> <input type="submit" value="Send Email" name="submit"> </fieldset> <?php } require_once('footer.php'); ?> I am looking to add a comment area to pages that are created with data that is pulled off of a database. I am looking for something like the forums on this site, but not as complex. I was thinking about attempting to use a text file to hold the comments for each ID number that is in my database and then displaying those comments when the ID number is called. I'm not sure how I would go about making a function that would search if there was a text file for that ID number and if not to create one. I'm not even sure if this is the best way to go about it but I know if I put all the comments into a database it will get rather large rather quickly. Any pointers and good tutorials would be welcome. Sorry if it sounds as if this post is rambling, I think I need to step away from the computer for a bit. Thanks 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 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=318858.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 Hi php freaks I've been learning php, but what confuses me are the arrays. I have ini file, i want to get the data from file and add it to the database. Every section makes a new table and all they keys are added with their values. I figured out how to get the keys and how to see the values, but how can i get the name of the sections. Furthermore, how do i know what keys belong to what section. I am really grateful for person who helps me to realize how to be a good friend with those complicated arrays. Hey guys so I am making an App website and somehow need to make a developer section. So like developers can come and setup their app name,description etc. Then be able to program there own app and use like an API service to get the user username etc. So what would I need to let developers do a such thing like let them make an API key and all that is there some tutorial to make such service. (This will be an important feature to my website so please help, thanks)
I'm working on the following assignment and keep coming up with error messages.
"Warning: require(mysqli_connect_registrar.php): failed to open stream: No such file or directory in /home/students/r/b.richards/public_html/cis231/labs/sectionresults.php on line 3 I've included the code I have and any help would be appreciated. Thank you. Assignment Directions: Introduction This lab will demonstrate how to create a dynamic form that is created from database contents. And then that form will be used to pull results from the database, based on the user's selection.
STEP 1 - Create the Database Connection File In your labs directory, define a mysql_connect.php file for the registrar database (with the student | student credentials).
STEP 2 - Create the Form Define the form as sectionsearch.php. Create a dynamic form with a drop-down menu listing available courses by title. (Note: the courseID will be the value that is posted to the results page.)
Step 3 - Create the Results page Define the results page as sectionresults.php. Present the results of the query for sections (unless there are none—then show an appropriate message). If there are results, use an HTML table (dynamically-generated) to display available sections with the following information: Faculty last name Room number Class meeting day(s) Start time End time The information should be sorted by the faculty member's last name. Note: You will need to consult the structure of the database tables to determine which fields need to be drawn from which tables and how to join the appropriate tables needed for the query. Sectionsearch.php code:
<!doctype html>
<head> <body>
<form id="form1" name="form1" method="post" action="sectionresults.php">
<p>Courses
<p>
</form> mysql_connect.php code:
<!doctype html>
//Set database connection information
//Database connection
//Set the encoding sectionresults.php code:
<?php
$cat = "";
$q = "SELECT lastame, FROM faculty WHERE registrar = $cat ORDER BY lastname ASC"; Hello. Well I haven't any code for this, but its only a question. Do you think it would be possible for PHP, to make and image or draw one from just a blank JPG. Then placing text on the image. That is possible and quite simple. But do you think it is possible to say. Say if you have 3 different set of texts on the image. Click here for 1 Click here for 2 Click here for 3 And also for the script to link those text to different web addresses. But all still workable with a dynamic signature EG [ img ] [ / img ] Basically its a dynamic signature with links on it is what i am trying to say. Do you think its possible? Or am I thinking to big. I think it would be interesting and useful to many to make a do and don't section or pinned post for most sections.
Editable by admins and mods to keep organized
Like the phpfreaks bible of coding, best practices.
A lot of members post some valuable information that gets lost old posts or too hard to search for.
Everyone repeating themselves on bad practices or deprecated code, turning on error reporting and such.
Hi! I'd like to echo a text section from pageB.php to pageA.php Is it possible to mark it up somehow and tell the browser to echo the variable? I'm thinking something like this should work after some alteration: pageA: <?php echo pageb.php/variable; ?> pageB: <?php $variable = ***the content section I want to be displayed on pageA*** "; ?> I'd be very grateful if someone could help me out. (: I don't even really know how to title it. I have this piece of code, i wrote. it works with wordpress api but honestly i don't think that matters much. what it does, is pick $ci number of categories, and then picks 2 posts from each category. it then assigns the image in/attached to that post to an array, to be used later. this all works fine, the problem is when it picks a post that doesn't have an image. right now, it can't tell that. writing in a bit to be able to tell whether there is an image or not should be easy. i'm thinking it can be as basic as file_exists or as complicated as parsing the post. the part i have the problem with - is how do i make it go back and pick another post/category when it comes up short? more than once? i want it to keep going back until it comes up with an image. i'd rather not expand the search any farther than necessary Code: [Select] <?php if ( false === ( $scroller = get_transient( $stransient ) ) ) { if (!is_array($scroller) || count($scroller)==0) { $args = array( 'type' => 'post', 'parent' => 18, 'exclude' => 63, 149, 278, 62 ); $companies = get_categories( $args ); while (count($companies) > $ci){unset($companies[array_rand($companies)]);} shuffle($companies);$truckco= array(); foreach ($companies as $company){ $argus = array('numberposts' => 2, 'orderby' => 'rand', 'post_type' => 'post', 'category' => $company->cat_ID ); $listings = get_posts($argus); foreach($listings as $tn=>$post) { $truckco[$company->slug]['truck_'. $tn]['image'] = get_the_image( array( 'image_scan' => true, 'format' => 'array', 'width' => '172', 'height' => '129' ) ); $truckco[$company->slug]['truck_'. $tn]['pid'] = $post->ID; } } ?> thank you Can i open a pdf within a page? e.g. within <td> or <table> of htmls so that it appears on a section of a page where someone can just read through and still able to browse the web page. I dont want the PDF downloading or taking the whole page or even opening a new window and filling it. Thanks in advance. Hi, first of all I am trying to do a section hidden from guests on a website. I have groups for each user (groups_admin, _mod, _member etc.)
I have it so ADMIN only view content at the moment, but not sure how to add GROUPS_MOD & GROUPS_MEMBER:
<?php echo $user_data['group_id'] == GROUPS_ADMIN ? 'content' : ''; ?>Secondly, where the content section is, I have HTML placed inside it which works fine, but it also has some PHP code. How would I get it so the php code works? This is what I have... <?php echo $user_data['group_id'] == GROUPS_ADMIN ? '<form method="post" action="<?php echo get_url(\'/products/\', $product[\'category_id\'], $product[\'product_id\'], $product[\'product_name\']); ?>?action=review">' : ''; ?>As you can see the form action line has a php url to generate the relevant link for a specific product. If anyone has any suggestions or can help in any way that would be much appreictaed. Cheers, Paul Hey everyone! Thanks for taking the time to help. I have two files..a membership area and a commenting section. I am fairly new at these subjects but I am a quick learner. First off, I need help figuring out why my "register.php" in the members area file isn't working properly, everything looks to be ok but maybe I have been working on this too long. Quite frankly I can't check and see if all of the other scripts are correct because I can't get past the "register.php". So if you all wouldn't mind helping me out on this part, I would greatly appreciate it Secondly, I have a commenting section and in the "demo.php", there is a warning that appears as follows: "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.8.1\www\comments\demo.php on line 17 " If someone could tell me what is missing or help me figure out what to do in simple terms, I would greatly appreciate that as well. Thanks! Gene [attachment deleted by admin] Hi, I have some queries that update some statistics in a table I have. I need these queries to run only after 15 seconds have passed however. This way if the user leaves before the 15 seconds, the queries won't run. I've tried using Sleep, however it seems to just stop all the code all together for the allotted time. There must be a way to do this. |