Jump to content
Larry Ullman's Book Forums


  • Posts

  • Joined

  • Last visited

Everything posted by grahamgr3

  1. I am building a site from the info in this book. And the post I am writing as you read this has a toolbar at the top that allows me to add bold to text, and other cool options. Where could I get a toolbar like this for my website, so I can add it to form fields.? The main thing I am looking for is adding paragraphs when people type 2 carriage returns on their keyboard. So that the text area form field behaves like as if you are typing in a word processing document. Adding bold to text, italics, and underline would be great too, but as a beginner I can accept if the paragraphs is all I can handle code-wise. I do know some javascript, so if coding it involves that I might be able to. Any ideas on how to go about this would be wonderful!
  2. I am using a live site and the error message shouldn't be displayed on my website but it is. I don't know why. The error message it shows online is Could not connect to MySQL: Access denied for user 'moreaw32_grah2'@'localhost' (using password: YES) . When other errors occur on my site it does not show the detailed message. I don't want it to show the details of my database like my user name which it does show. Here is the line of code in my connection script. $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error()) What can I do to prevent this.
  3. I found the answer to my own question, I would have deleted the post but I couldn't find the delete option on the site.
  4. The select query below returns 1 row when it should be 3. I am pretty sure it is because of the AVG(k.sumtotal) field. If I rewrite the query and take out that AVG(k.sumtotal) column and take out the FROM inv_ratings AS k, I get my 3 rows. I looked online for hours trying to find information about returning results using the AVG clause and didn't find much. Do I have to use a group by clause, I tried that and only get errors. If it is a group by clause please type the exact group by clause to use if you could. thank you. $p = "SELECT i.invention_id, i.inv_title, i.date_submitted, i.category_id, i.approved, c.category_id, c.category, u.image_name, AVG(k.sumtotal) FROM inv_ratings AS k INNER JOIN inventions AS i USING (invention_id) INNER JOIN categories AS c USING (category_id) INNER JOIN images AS u USING (invention_id) WHERE c.category_id = $cat AND i.approved = 'approved' HAVING u.image_name < 2 ORDER BY date_submitted DESC LIMIT $start, $display"; $q = mysqli_query($dbc, $p) or trigger_error("Query: $p\n<br />mysqli Error: " . mysqli_error($dbc));
  5. ok , so then should we include this line of code on every mysqli_query() we do on our site, including, select, insert, update, delete? or trigger_error("Query: $i\n<br />mysqli Error: " . mysqli_error($dbc));
  6. In the following code would you leave the part in where it says or trigger error and so on, on a live site mysqli_query($dbc, $i) or trigger_error("Query: $i\n<br />mysqli Error: " . mysqli_error($dbc));
  7. In the site I am creating, I have an images table that allows for duplicate values (2 only) which are the foreign key article_id. You see each article_id can have up to two images displayed on it. So in my images table each image_id row will have 2 article_id's in it. The trouble is that when I display results on my website using this data, I get double results. The query makes 2 rows appear, when I only want 1 to show on my page. When going through my code the computer sees 2 article_id's in the images table and displays 2 rows when I only want one. I tried using the DISTINCT keyword in my query but that didn't work. Is there a better workaround for this, I really want to keep it like this, 2 images per article. Is there a way to change my table and make it more proper or make php only display 1 result. Or should I just create a separate images table for the second images? $p = "SELECT DISTINCT i.article_id, i.inv_title, i.date_submitted, i.category_id, c.category_id, i.approved, c.category, u.image_name FROM articles AS i INNER JOIN categories AS c USING (category_id) INNER JOIN images AS u USING (article_id) WHERE c.category_id = $cat AND i.approved = 'approved' ORDER BY date_submitted DESC LIMIT $start, $display";
  8. I found the error, I forgot to put the $start variable in my sql query in the limit clause.
  9. I have about 12 results and I set the $display variable to 5 so I should get 5 results per page and 3 page numbers , but my page still displays 12 results on the first page, yet displays the 3 page numbers correctly. I am pretty sure the problem is because of the sql query that has a Group By clause, it groups the threads and I think that is the problem, but if I take the Group By out, the results aren't complete. It's as if the page numbers aren't connecting to the sql query results. How could I fix this.
  10. I am building a forum from the example in the book, and I am having trouble getting the page numbers to work like they should, right now the thread results don't update when you click on other page numbers, it is always the same query results on every page. Here is some code where I think the problem is, but I can't find it. I would post the whole page's code, but I have done that before and didn't get many helpers for that. The query I am using is $sql = "SELECT t.thread_id, t.subject, u.username, COUNT(p.post_id) - 1 AS responses, MAX(DATE_FORMAT($last, '%e-%b-%y %l:%i %p')) AS last, MIN(DATE_FORMAT($first, '%e-%b-%y %l:%i %p')) AS first, w.forum_id FROM threads AS t INNER JOIN posts AS p USING (thread_id) INNER JOIN forums AS w ON t.forum_id = w.forum_id INNER JOIN users AS u ON t.user_id = u.user_id WHERE w.forum_id=$forumid AND t.lang_id = {$_SESSION['lid']} GROUP BY (p.thread_id) ORDER BY last DESC"; $query = mysqli_query ($dbc, $sql); At the top of my forum.php page I am using this code to identify which forum the threads belong to. if (isset($_GET['id']) && is_numeric($_GET['id'])){ $forumid = $_GET['id']; } elseif (isset($_POST['id']) && is_numeric($_POST['id'])) { $forumid = $_POST['id']; } else { echo '<p class="error">This page has been accessed in error.</p>'; include ('includes/footer.html'); exit(); } Here are the page links, modified to include the forum_id in the url. if ($pages > 1){ echo '<br /><p class="center4">'; $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button: if ($current_page != 1) { echo '<a href="forum.php?s=' . ($start - $display) . '&p=' . $pages . '&id='.$forumid.'">Previous</a> '; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="forum.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&id='.$forumid.'">' . $i . '</a> '; } else { echo $i . ' '; } } // End of FOR loop. // If it's not the last page, make a Next button: if ($current_page != $pages) { echo '<a href="forum.php?s=' . ($start + $display) . '&p=' . $pages . '&id='.$forumid.'">Next</a>'; } echo '</p>'; // Close the paragraph. } // End of links section. thanks for taking a look.
  11. I tinkered with the Session variable idea, but my being new at php, I couldn't figure out the best way to go about it. So I stuck with the shuffle function, the code I am using is below. The only problem with the code below is that when the second image comes in, it kind of jumps in the browser sometimes, I don't know why it does that. And when I have an error in my page the images show up multiple times on the error page. function array_random2($arr){ shuffle($arr); return $arr[0]; } $imglogo1 = '<img src="images/logo5214.jpg" alt="logo" class="logo2">'; $imglogo2 = '<img src="images/logo5213.jpg" alt="logo" class="logo2">'; $a = array($imglogo1, $imglogo2); echo array_random2($a);
  12. if I set the $display variable at 7. I should get 7 results with a Page link to the next page with the last result, instead it ignores the 8th result and doesn't give me any page links. Could it be that you have to set the display variable to an even number like 10 for it to work properly.
  13. I created a script that uses the pagination example in the book, and what is happening is that, I have 8 results, if I set the $display variable at 7. I should get a page number to the second page that has the eighth result. But I don't get that, instead it totally ignores the 8th result. I looked at the code and thought the problem might be where it says $pages = ceil($records/$display), because it rounds it off, maybe that's why I lose a result. Any idea what could be causing the problem, it is the main pagination script in the book. Maybe I have an error, but after looking for hours I can't find it. $q = "SELECT COUNT(i.invention_id), c.category_id FROM inventions AS i INNER JOIN categories AS c USING (category_id) WHERE category_id = $cat"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; // Calculate the number of pages... if ($records > $display) { // More than 1 page. $pages = ceil($records/$display); } else { $pages = 1; }
  14. After reading this book and practicing, I am creating a site that has more than one main logo, I want them to alternate when the page changes to another page or is refreshed. So I thought of using the ternary operator, but I can't get it to work. Since there is no while loop involved in my header page where this code will go, I guess that's why it doesn't work. I got it to work with php's shuffle function, but that doesn't create the effect I want exactly. Anyways here is where I am at with this, any help to get this working would be appreciated. <header> $imglogo1 = '<img src="images/logo5214.jpg" alt="logo" class="logo2">'; $imglogo2 = '<img src="images/logo5213.jpg" alt="logo" class="logo2">'; $bg = $imglogo1; $bg = ($bg==$imglogo1 ? $imglogo2 : $imglogo1); </header>
  15. I want to display images on my page from a folder called forumimages. Right now it is just showing broken images. I have tried changing the directory and it doesn't work. My images are in the folder and they are jpegs. Here is the code. $directory = "../../forumimages/"; //get all image files with a .jpg extension. $images = glob($directory . "*.jpg"); //print each file name foreach($images as $image) { echo '<img src="' . $directory . '/' . $image . '" />'; }
  16. I am working on a site, and using the scripts in this book. I keep getting the error this page has been accessed in error. The script should insert a record into the database, instead it doesn't do any validation or anything else, it just gives the error message. I thought it might be a problem with the database but I can't find the problem. Any ideas.
  17. I am trying to implement a search feature to a forum I am creating and I want users to be able to search through posts. So far users type in the search terms in a form, and they go through to my $_GET['terms']. The problem is that the IN BOOLEAN MODE search only returns posts that start with or end with one of the search terms users type into the form. I want it so that the search can also return phrases that are within posts, not necessarily starting or ending with. I have tried the boolean mode operators in all sorts of ways but it doesn't work. Is it possible to use fulltext searches in this way, or should I try a different method. Here is my Mysql query I am using: $terms = mysqli_real_escape_string($dbc, htmlentities(strip_tags($_GET['terms']))); $q = "SELECT m.message, m.posted_on, s.thread_id, s.subject FROM posts AS m LEFT JOIN threads AS s USING (thread_id) WHERE MATCH (message, subject) AGAINST('$terms*' IN BOOLEAN MODE)";
  18. I have built a forum for my own website thanks to the forum example in this book in chapter 17. Now I want the capability to search through posts and show the results of the search. I modified the search.php script included in the course files. I tested it and it doesn't work properly, the $_GET['terms'] doesn't get set when I type in search terms and click search. I tested it by echoing out 'hello' after the isset($_GET['terms']) . I don't know why it isn't set though, in the address bar it is written search.php?terms=test&submit=Submit <?php # Script 17.8 - search.php // This page displays and handles a search form. // Include the HTML header: // Show the search form: echo '<form action="search.php" method="get" accept-charset="utf-8"> <p><em>Search </em>: <input name="terms" type="text" size="30" maxlength="60" '; // Check for existing value: if (isset($_GET['terms'])) { echo 'value="' . htmlspecialchars($_GET['terms']) . '" '; } // Complete the form: echo '/><input name="submit" type="submit" value="' . $words['submit'] . '" /></p></form>'; if (isset($_GET['terms'])) { // Handle the form. echo 'hello'; // Clean the terms: $terms = mysqli_real_escape_string($dbc, htmlentities(strip_tags($_GET['terms']))); // Run the query... $q = "SELECT message FROM posts WHERE MATCH (message) AGAINST ('test' IN BOOLEAN MODE)"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { $row = mysqli_fetch_array($r, MYSQLI_ASSOC); echo '<h2>Search Results</h2>'; echo '<p>' . $row['message'] . '</p>'; } else { echo '<p>No results found.</p>'; } } ?>
  19. I want to have a forum that has several topics, I want each forum topic to have a forum id. So they are like separate forums. Here are the columns I though up for my new forums table which will manage each individual forum topic. forum_id, thread_id, user_id, lang_id, title, description, Are those columns sufficient, I want to build this table correctly from the start.
  20. I want to integrate the forum example in the book into my website, except I would modify it so that I could have multiple forums with different topics on my site. What I want to know is what columns and tables do you think I should add to my forum database. To add to the example in the book, I thought of creating a new forums table, and in it having the forum_id column, as well as the thread_id foreign key column. I am new at this so if you have any suggestions at populating my forums table that would be great.
  21. I am creating a site using the registration system in chapter 18, and I am using the output buffer on every page, the ob_start() is included in every page via the header.html file. In the book it says that if we use the output buffer we won't get headers already sent error messages. But I just tested it and put a space before the starting <?php tag. And I got the following error. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/ why does it give an error message.
  22. Yes I have the charset tag set to utf-8, and I have the content-type header via php. why isn't it working?
  23. I have just typed out index.php for chapter 17, and the language drop down menu displays funny characters instead of the language specific letters. I typed the scripts as shown in the book. How can I debug this, is it my Xampp settings, I checked and it says the language is set to US in Xampp. In the book it says to save my page using utf-8 encoding. I don't know if that is the problem, I just saved my index.php page with the name index.php, in dreamweaver I don't see an option for the encoding to use for the page. In my header file the encoding is set to utf-8 and that file is included in index.php, so won't that do it.
  24. In this book in chapter 2 script 2.4 index.php. It says to include the configuration file: require('./includes/config.inc.php'); How can you reference a file with ./, shouldn't it be ../ I tried it and it doesn't work. Is this a mistake in the book?
  • Create New...