
light87
Members-
Posts
14 -
Joined
-
Last visited
Never
Everything posted by light87
-
Browser RSS Newsfeed Inconsistencies Using MySQL Database and PHP files
light87 replied to light87's topic in MySQL Help
The problems with this feed are mostly solved. I fixed the problems with Google Chrome, Mozilla and Opera by getting the RSS feed subscription extension for each one. I still can't get IE9 to work properly, and decided that it is a problem with their browser design (the problem with IE9 is that it shows 1 too many listings). If anybody knows how to fix the problem with IE9 please let me know. -
Browser RSS Newsfeed Inconsistencies Using MySQL Database and PHP files
light87 replied to light87's topic in MySQL Help
Just load the following link into each of the 3 main browsers (IE9, Mozilla and Firefox) and you will notice that IE9 shows one more listing in the feed compared to the other two: http://www.cheapcostdiamonds.com/X_Database_Chapter12_Page675_newsfeed_final.php Thanks -
Browser RSS Newsfeed Inconsistencies Using MySQL Database and PHP files
light87 replied to light87's topic in MySQL Help
I was joking about the letter to Microsoft. The image that contains a marked up screen shot showing the 6 items was attached earlier, and it is attached here again. Thank you. -
Browser RSS Newsfeed Inconsistencies Using MySQL Database and PHP files
light87 replied to light87's topic in MySQL Help
Thanks for the reply! There is probably a design problem with IE9. I changed the setting for how frequently IE9 updates feeds to 15 minutes and loaded the following URL into the IE9, Mozilla, and Opera browsers and refreshed all of them several times during the last day or so. IE9 still shows 6 items instead of the 5 that are shown in Mozilla and Opera. The URL is: http://www.cheapcostdiamonds.com/X_Database_Chapter12_Page675_newsfeed_final.php Maybe I should write a letter to Microsoft? -
Hello: I have a test website that creates an RSS feed from PHP coding and a MySQL database. I have noticed some inconsistencies across 3 major browsers and would like to know if anybody can help me out. I don't know if the problems are due to bad Browser Design(s) and/or possible coding errors in my files. I used these six files: Aliensaway675_Database_TableSetup_aliens_abduction_Chapter12_Page675.sql index.php X_Database_Chapter12_Page675_connectvars_final.php X_Database_Chapter12_Page675_newsfeed_final.php X_Database_Chapter12_Page675_report_final.php X_Database_Chapter12_Page675_style_final.css I noticed different Browser behaviors for the newsfeed. More specifically, I pasted the following URL into the Internet Explorer 9, Mozilla version 11.0, and Opera version 11.61 browsers: http://www.cheapcostdiamonds.com/X_Database_Chapter12_Page675_newsfeed_final.php Again, this is a test site (I am not trying to sell anything). I then went directly into my GoDaddy's MySQL database after adding a few reports and deleted a few reports until there were 5 sightings left for the feed (i.e. 5 records in the MySQL database). I refreshed the database in GoDaddy, then refreshed all three browsers and noticed some differences. These are shown in the 3 screenshots that I attached. More specifically: 1) IE9 showed more results in the feed that should have been (there are 6, there should only be 5). The "Aliens Abducted Me - Newsfeed" is a clickable link (which is what we want it to be). 2) Mozilla showed "Aliens Abducted Me - Newsfeed", but it is not clickable. It does show the correct number of sightings. 3) Opera showed "Aliens Abducted Me - Newsfeed", but it is not clickable. It does show the correct number of sightings. My question to the community is: Are these differences due to the lack of consistencies in the Browser designs or did I make errors in the files? The sql file is: CREATE TABLE `aliens_abduction` ( `abduction_id` INT AUTO_INCREMENT, `first_name` VARCHAR(30), `last_name` VARCHAR(30), `when_it_happened` DATE, `how_long` VARCHAR(30), `how_many` VARCHAR(30), `alien_description` VARCHAR(100), `what_they_did` VARCHAR(100), `fang_spotted` VARCHAR(10), `other` VARCHAR(100), `email` VARCHAR(50), PRIMARY KEY (`abduction_id`) ); INSERT INTO `aliens_abduction` VALUES (1, 'Alf', 'Nader', '2000-07-12', 'one week', 'at least 12', 'It was a big non-recyclable shiny disc full of what appeared to be mutated labor union officials.', 'Swooped down from the sky and snatched me up with no warning.', 'no', 'That\'s it.', '[email protected]'); INSERT INTO `aliens_abduction` VALUES (2, 'Don', 'Quayle', '1991-09-14', '37 seconds', 'dunno', 'They looked like donkeys made out of metal with some kind of jet packs attached to them.', 'I was sitting there eating a baked potatoe when "Zwoosh!", this beam of light took me away.', 'yes', 'I really do love potatos.', '[email protected]'); INSERT INTO `aliens_abduction` VALUES (3, 'Rick', 'Nixon', '1969-01-21', 'nearly 4 years', 'just one', 'They were pasty and pandering, and not very forgiving.', 'Impeached me, of course, then they probed me.', 'no', 'I\'m lonely.', 'rnixon@not'); INSERT INTO `aliens_abduction` VALUES (4, 'Belita', 'Chevy', '2008-06-21', 'almost a week', '27', 'Clumsy little buggers, had no rhythm.', 'Tried to get me to play bad music.', 'no', 'Looking forward to playing some Guitar Wars now that I\'m back.', '[email protected]'); INSERT INTO `aliens_abduction` VALUES (5, 'Sally', 'Jones', '2008-05-11', '1 day', 'four', 'green with six tentacles', 'We just talked and played with a dog', 'yes', 'I may have seen your dog. Contact me.', '[email protected]'); INSERT INTO `aliens_abduction` VALUES (6, 'Meinhold', 'Ressner', '2008-08-10', '3 hours', 'couldn\'t tell', 'They were in a ship the size of a full moon.', 'Carried me to the top of a mountain and dropped me off.', 'no', 'Just want to thank those fellas for helping me out.', '[email protected]'); INSERT INTO `aliens_abduction` VALUES (7, 'Mickey', 'Mikens', '2008-07-11', '45 minutes', 'hundreds', 'Huge heads, skinny arms and legs', 'Read my mind,', 'yes', 'I\'m thinking about designing a helmet to thwart future abductions.', '[email protected]'); INSERT INTO `aliens_abduction` VALUES (8, 'Shill', 'Watner', '2008-07-05', '2 hours', 'don\'t know', 'There was a bright light in the sky, followed by a bark or two.', 'They beamed me toward a gas station in the desert.', 'yes', 'I was out of gas, so it was a pretty good abduction.', '[email protected]'); The code for X_Database_Chapter12_Page675_connectvars_final.php is: <?php //3,08,12 //Filename:C:,HeadFirst_PHP_MYSQL,Chapter12, //X_Database_Chapter12_Page675_connectvars_final.php // Define database connection constants define('DB_HOST', 'KEPTPRIVATE'); define('DB_USER', 'KEPTPRIVATE'); define('DB_PASSWORD', 'KEPTPRIVATE'); define('DB_NAME', 'KEPTPRIVATE'); ?> The code for X_Database_Chapter12_Page675_newsfeed_final.php is: <?php header('Content-Type: text/xml'); ?><?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?><rss version="2.0"> <channel> <title>Aliens Abducted Me - Newsfeed</title> <link>http://www.cheapcostdiamonds.com/</link> <description>Alien abduction reports from around the world courtesy of Owen and his abducted dog Fang.</description> <language>en-us</language> <?php require_once('X_Database_Chapter12_Page675_connectvars_final.php'); //2,4,10 //Filename:C:,HeadFirst_PHP_MYSQL,Chapter12, //X_Database_Chapter12_Page675_newsfeed_final.php // Connect to the database $dbc = mysqli_connect('DB_HOST', 'DB_USER', 'DB_PASSWORD', 'DB_NAME'); // Retrieve the alien sighting data from MySQL $query = "SELECT abduction_id, first_name, last_name, DATE_FORMAT(when_it_happened,'%a, %d %b %Y %T') AS when_it_happened_rfc, " . "alien_description, what_they_did FROM aliens_abduction ORDER BY when_it_happened DESC"; $data = mysqli_query($dbc, $query); // Loop through the array of alien sighting data, formatting it as RSS while ($row = mysqli_fetch_array($data)) { // Display each row as an RSS item echo '<item>'; echo ' <title>' . $row['first_name'] . ' ' . $row['last_name'] . ' - ' . substr($row['alien_description'], 0, 32) . '...</title>'; echo ' <link>http://www.cheapcostdiamonds.com/index.php?abduction_id=' . $row['abduction_id'] . '</link>'; echo ' <pubDate>' . $row['when_it_happened_rfc'] . ' ' . date('T') . '</pubDate>'; echo ' <description>' . $row['what_they_did'] . '</description>'; echo '</item>'; } ?></channel></rss> The code for X_Database_Chapter12_Page675_report_final.php is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Aliens Abducted Me - Report an Abduction</title> <link rel="stylesheet" type="text/css" href="X_Database_Chapter12_Page675_style_final.css" /> </head> <body> <h2>Aliens Abducted Me - Report an Abduction</h2> <?php require_once('X_Database_Chapter12_Page675_connectvars_final.php'); if (isset($_POST['submit'])) { // Connect to the database $dbc = mysqli_connect('DB_HOST', 'DB_USER', 'DB_PASSWORD', 'DB_NAME'); // Grab the report data from the POST $first_name = mysqli_real_escape_string($dbc, trim($_POST['firstname'])); $last_name = mysqli_real_escape_string($dbc, trim($_POST['lastname'])); $email = mysqli_real_escape_string($dbc, trim($_POST['email'])); $when_it_happened = mysqli_real_escape_string($dbc, trim($_POST['whenithappened'])); $how_long = mysqli_real_escape_string($dbc, trim($_POST['howlong'])); $how_many = mysqli_real_escape_string($dbc, trim($_POST['howmany'])); $alien_description = mysqli_real_escape_string($dbc, trim($_POST['aliendescription'])); $what_they_did = mysqli_real_escape_string($dbc, trim($_POST['whattheydid'])); $fang_spotted = mysqli_real_escape_string($dbc, trim($_POST['fangspotted'])); $other = mysqli_real_escape_string($dbc, trim($_POST['other'])); if (!empty($first_name) && !empty($last_name) && !empty($when_it_happened) && !empty($how_long) && !empty($what_they_did)) { // Write the data to the database $query = "INSERT INTO aliens_abduction (first_name, last_name, email, when_it_happened, how_long, how_many, alien_description, what_they_did, fang_spotted, other) " . "VALUES ('$first_name', '$last_name', '$email', '$when_it_happened', '$how_long', '$how_many', '$alien_description', '$what_they_did', '$fang_spotted', '$other')"; mysqli_query($dbc, $query); // Confirm success with the user echo '<p>Thanks for adding your abduction.</p>'; echo '<p><a href="index.php"><< Back to the home page</a></p>'; mysqli_close($dbc); exit(); } else { echo '<p class="error">Please enter your full name, date of abduction, how long you were abducted, and a brief description of the aliens.</p>'; } } ?> <p>Share your story of alien abduction:</p> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="firstname">First name:</label> <input type="text" id="firstname" name="firstname" value="<?php if (!empty($first_name)) echo $first_name; ?>" /><br /> <label for="lastname">Last name:</label> <input type="text" id="lastname" name="lastname" value="<?php if (!empty($first_name)) echo $last_name; ?>" /><br /> <label for="email">What is your email address?</label> <input type="text" id="email" name="email" value="<?php if (!empty($email)) echo $email; ?>" /><br /> <label for="whenithappened">When did it happen?</label> <input type="text" id="whenithappened" name="whenithappened" value="<?php if (!empty($when_it_happened)) echo $when_it_happened; else echo 'YYYY-MM-DD'; ?>" /><br /> <label for="howlong">How long were you gone?</label> <input type="text" id="howlong" name="howlong" value="<?php if (!empty($how_long)) echo $how_long; ?>" /><br /> <label for="howmany">How many did you see?</label> <input type="text" id="howmany" name="howmany" value="<?php if (!empty($how_many)) echo $how_many; ?>" /><br /> <label for="aliendescription">Describe them:</label> <input type="text" id="aliendescription" name="aliendescription" size="32" value="<?php if (!empty($alien_description)) echo $alien_description; ?>" /><br /> <label for="whattheydid">What did they do to you?</label> <input type="text" id="whattheydid" name="whattheydid" size="32" value="<?php if (!empty($what_they_did)) echo $what_they_did; ?>" /><br /> <label for="fangspotted">Have you seen my dog Fang?</label> Yes <input id="fangspotted" name="fangspotted" type="radio" value="yes" <?php echo ($fang_spotted == 'yes' ? 'checked="checked"' : ''); ?> /> No <input id="fangspotted" name="fangspotted" type="radio" value="no" <?php echo ($fang_spotted == 'no' ? 'checked="checked"' : ''); ?> /><br /> <img src="fang.jpg" width="100" height="175" alt="My abducted dog Fang." /><br /> <label for="other">Anything else you want to add?</label> <textarea id="other" name="other"> <?php if (!empty($other)) echo $other; ?> </textarea><br /> <input type="submit" value="Report Abduction" name="submit" /> </form> </body> </html> The code for X_Database_Chapter12_Page675_style_final.css is: /* Filename:C:,HeadFirst_PHP_MYSQL,Chapter12, X_Database_Chapter12_Page675_style_final.css */ .error { font-weight:bold; color:#FF0000; } table { border:1px solid #DDDDDD; border-collapse:collapse; } tr.heading { font-size:large; color:#006600; } td { border:1px solid #DDDDDD; } form label { display:inline-block; width:225px; font-weight:bold; } a { text-decoration:none; font-weight:bold; } a:link { color:#006600; } a:hover { background-color:#EEEEEE; } a:visited { color:#002200; } a:active { color:#009900; } I have 4 attachments. 17822_.php
-
Hello: I'm having problems with a newsfeed. More specifically, it is a "Test Drive" exercise for the book "Head First Php and MySQL" by Beighly and Morrison on page 675. The website that I use does not try to sell anything and is only used as a test site. There are 6 files associated with this exercise. The SQL file is: CREATE TABLE `aliens_abduction` ( `abduction_id` INT AUTO_INCREMENT, `first_name` VARCHAR(30), `last_name` VARCHAR(30), `when_it_happened` DATE, `how_long` VARCHAR(30), `how_many` VARCHAR(30), `alien_description` VARCHAR(100), `what_they_did` VARCHAR(100), `fang_spotted` VARCHAR(10), `other` VARCHAR(100), `email` VARCHAR(50), PRIMARY KEY (`abduction_id`) ); INSERT INTO `aliens_abduction` VALUES (1, 'Alf', 'Nader', '2000-07-12', 'one week', 'at least 12', 'It was a big non-recyclable shiny disc full of what appeared to be mutated labor union officials.', 'Swooped down from the sky and snatched me up with no warning.', 'no', 'That\'s it.', '[email protected]'); INSERT INTO `aliens_abduction` VALUES (2, 'Don', 'Quayle', '1991-09-14', '37 seconds', 'dunno', 'They looked like donkeys made out of metal with some kind of jet packs attached to them.', 'I was sitting there eating a baked potatoe when "Zwoosh!", this beam of light took me away.', 'yes', 'I really do love potatos.', '[email protected]'); INSERT INTO `aliens_abduction` VALUES (3, 'Rick', 'Nixon', '1969-01-21', 'nearly 4 years', 'just one', 'They were pasty and pandering, and not very forgiving.', 'Impeached me, of course, then they probed me.', 'no', 'I\'m lonely.', 'rnixon@not'); INSERT INTO `aliens_abduction` VALUES (4, 'Belita', 'Chevy', '2008-06-21', 'almost a week', '27', 'Clumsy little buggers, had no rhythm.', 'Tried to get me to play bad music.', 'no', 'Looking forward to playing some Guitar Wars now that I\'m back.', '[email protected]'); INSERT INTO `aliens_abduction` VALUES (5, 'Sally', 'Jones', '2008-05-11', '1 day', 'four', 'green with six tentacles', 'We just talked and played with a dog', 'yes', 'I may have seen your dog. Contact me.', '[email protected]'); INSERT INTO `aliens_abduction` VALUES (6, 'Meinhold', 'Ressner', '2008-08-10', '3 hours', 'couldn\'t tell', 'They were in a ship the size of a full moon.', 'Carried me to the top of a mountain and dropped me off.', 'no', 'Just want to thank those fellas for helping me out.', '[email protected]'); INSERT INTO `aliens_abduction` VALUES (7, 'Mickey', 'Mikens', '2008-07-11', '45 minutes', 'hundreds', 'Huge heads, skinny arms and legs', 'Read my mind,', 'yes', 'I\'m thinking about designing a helmet to thwart future abductions.', '[email protected]'); INSERT INTO `aliens_abduction` VALUES (8, 'Shill', 'Watner', '2008-07-05', '2 hours', 'don\'t know', 'There was a bright light in the sky, followed by a bark or two.', 'They beamed me toward a gas station in the desert.', 'yes', 'I was out of gas, so it was a pretty good abduction.', '[email protected]'); The X_Database_Chapter12_Page675_connectvars_final.php file is: <?php //3,08,12 //Filename:C:,HeadFirst_PHP_MYSQL,Chapter12, //X_Database_Chapter12_Page675_connectvars_final.php // Define database connection constants define('DB_HOST', 'KEPTPRIVATE'); define('DB_USER', 'KEPTPRIVATE'); define('DB_PASSWORD', 'KEPTPRIVATE'); define('DB_NAME', 'KEPTPRIVATE'); ?> The css file is: /* Filename:C:,HeadFirst_PHP_MYSQL,Chapter12, X_Database_Chapter12_Page675_style_final.css */ .error { font-weight:bold; color:#FF0000; } table { border:1px solid #DDDDDD; border-collapse:collapse; } tr.heading { font-size:large; color:#006600; } td { border:1px solid #DDDDDD; } form label { display:inline-block; width:225px; font-weight:bold; } a { text-decoration:none; font-weight:bold; } a:link { color:#006600; } a:hover { background-color:#EEEEEE; } a:visited { color:#002200; } a:active { color:#009900; } 17763_.php 17764_.php 17765_.php
-
This will not work, since my Website uses the "Strict" DTD (Document Type Declaration). I found out that if you are using Strict for the DTD, then frames or iframes are not allowed. The reference for this is: See "Head First HTML with CSS & HTML" by O'Reilly Books, page 642 "The frameset DOCTYPE's are considered to be transitional, so you can't have frames and be strict." There has to be another way. Thank you.
-
Hello: You stated: "...all you need to do is change src attribute of frame tag using php..." How do you change the src attribute of frame tag using php? In other words, what is the php coding to accomplish this? Thank you.
-
Hello: I thought that use of Iframes blocks google and other entities from crawling your site. I forgot to mention that I have several different links that sell different products from different Websites. Buying a new Domain name is not an option if you want to sell more than one product on each page, and the links go to different Websites. I would appreciate the help.
-
I have a Website that has several affiliate links that I would like to cloak. More specifically, when a user clicks on one of the links, I would like the Web Browser to reveal a URL that does not have "affiliate" in the name. My Website is http://www.website-kept-private.com, which is a fictitious Website (I have kept the true name of the Website private to keep in accordance with the terms of this forum). I wish to use PHP coding to employ a link (not an entire page or Website) redirect on one of the pages. <p>This is a great opportunity, <a href="http://www.website-kept-private.com/recommends/software-mobile/index.php">so forth and so on</a></p> Obviously, I created two sub-directories in the Website: The 1st is "recommends", and the 2nd is "software-mobile". The file "index.php" is placed under the "software-mobile" sub-directory. The entire coding for "index.php" is: <?php header("Location: http://Affiliatexyz123.Product-To-Sell.hop.clickbank.net/"); exit; ?> Of course, Affiliatexyz123 is a fictitious Affiliate I.D. Of course, Product-To-Sell is a fictitious product. This shows up on the bottom when you mouse over either the link or the picture: http://www.website-kept-private.com/recommends/software-mobile/index.php This shows up in the URL address when you click on the link or the icon: http://Product-To-Sell.com/?hop=Affiliatexyz123 The goal is that when the user clicks on the link, that "http://www.website-kept-private.com/recommends/software-mobile" shows up in the URL address, instead of revealing the Affiliate I.D. (which is Affiliatexyz123). Unfortunately, it doesn't. I have Linux hosting through GoDaddy. It seems as though GoDaddy only supports entire page redirects or entire Website redirects. Maybe I'm wrong. If GoDaddy does not support single link redirects, who does? I would appreciate the help.
-
Hello: I am trying to use a search form to search a Database. When I click on the submit button, I get the following error message: Parse error: syntax error, unexpected T_VARIABLE, expecting T_CASE or T_DEFAULT or '}' in /home/content/PRIVATE/html/riskyjobs_riskybusiness_Database_TableSetup_riskyjobs_Table_Chapter9_Page546_search_final.php on line 71 The php coding is as follows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Risky Jobs - Search</title> <link rel="stylesheet" type="text/css" href="style_Page546_final.css" /> </head> <body> <img src="riskyjobs_title.gif" alt="Risky Jobs" /> <img src="riskyjobs_fireman.jpg" alt="Risky Jobs" style="float:right" /> <h3>Risky Jobs - Search Results</h3> <?php // 1,5,10 // Filename:C:,HeadFirst_PHP_MYSQL,Chapter9, // riskyjobs_riskybusiness_Database_TableSetup_riskyjobs_Table_Chapter9_Page546_search_final.php // This function builds a search query from the search keywords and sort setting function build_query($user_search, $sort) { $search_query = "SELECT * FROM riskyjobs"; // Extract the search keywords into an array $clean_search = str_replace(',', ' ', $user_search); $search_words = explode(' ', $clean_search); $final_search_words = array(); if (count($search_words) > 0) { foreach ($search_words as $word) { if (!empty($word)) { $final_search_words[] = $word; } } } // Generate a WHERE clause using all of the search keywords $where_list = array(); if (count($final_search_words) > 0) { foreach($final_search_words as $word) { $where_list[] = "description LIKE '%$word%'"; } } $where_clause = implode(' OR ', $where_list); // Add the keyword WHERE clause to the search query if (!empty($where_clause)) { $search_query .= " WHERE $where_clause"; } // Sort the search query using the sort setting switch ($sort) { // Ascending by job title case 1: $search_query .= " ORDER BY title"; break; // Descending by job title case 2: $search_query .= " ORDER BY title DESC"; break; // Ascending by state case 3: $search_query .= " ORDER BY state"; break; // Descending by state case 4: $search_query .= " ORDER BY state DESC"; break; // Ascending by date posted (oldest first) case 5: $search_query .= " ORDER BY date_posted"; break; // Descending by date posted (newest first) case 6: $search_query .= " ORDER BY date_posted DESC"; break; default: // No sort setting provided, so don't sort the query } return $search_query; } // INTERIM INTERIM INTERIM INTERIM // This function builds heading links based on the specified sort setting function generate_sort_links($user_search, $sort) { $sort_links = ''; switch ($sort) { case 1: $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=2">Job Title</a></td><td>Description</td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=3">State</a></td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=5">Date Posted</a></td>'; break; case 3: $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=1">Job Title</a></td><td>Description</td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=4">State</a></td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=5">Date Posted</a></td>'; break; case 5: $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=1">Job Title</a></td><td>Description</td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=3">State</a></td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=6">Date Posted</a></td>'; break; default: $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=1">Job Title</a></td><td>Description</td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=3">State</a></td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=5">Date Posted</a></td>'; } return $sort_links; } // NEW STUFF PART 1 NEW STUFF PART 1 // Grab the sort setting and search keywords from the URL using GET $sort = $_GET['sort']; $user_search = $_GET['usersearch']; // Start generating the table of results echo '<table border="0" cellpadding="2">'; // Generate the search result headings echo '<tr class="heading">'; echo generate_sort_links($user_search, $sort); echo '</tr>'; // Connect to the database require_once('riskyjobs_riskybusiness_Database_TableSetup_riskyjobs_Table_Chapter9_Page546_connectvars_final.php'); $dbc = mysqli_connect('PRIVATE', 'PRIVATE', 'PRIVATE', 'PRIVATE'); // Query to get the total results $query = build_query($user_search, $sort); $result = mysqli_query($dbc, $query); // NEW STUFF PART 2 NEW STUFF PART 2 while ($row = mysqli_fetch_array($result)) { echo '<tr class="results">'; echo '<td valign="top" width="20%">' . $row['title'] . '</td>'; // changed $row['description'] . ' in the next line to substr($row['description'],0,100) . ' ... // on 12,31,09 echo '<td valign="top" width="50%">' . substr($row['description'],0,100) . ' ...</td>'; echo '<td valign="top" width="10%">' . $row['state'] . '</td>'; // changed $row['date_posted'] in the next line to substr($row['date_posted'],0,10) // on 12,31,09 echo '<td valign="top" width="20%">' . substr($row['date_posted'],0,10) . '</td>'; echo '</tr>'; } echo '</table>'; mysqli_close($dbc); ?> </body> </html> I would appreciate your help.
-
Hello: I'm having a problem with a search form. The error message that I get when the submit button is clicked is: Parse error: syntax error, unexpected T_VARIABLE, expecting T_CASE or T_DEFAULT or '}' in /home/content/PRIVATE/riskyjobs_riskybusiness_Database_TableSetup_riskyjobs_Table_Chapter9_Page546_search_final.php on line 69 The coding for the php file is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Risky Jobs - Search</title> <link rel="stylesheet" type="text/css" href="style_Page546_final.css" /> </head> <body> <img src="riskyjobs_title.gif" alt="Risky Jobs" /> <img src="riskyjobs_fireman.jpg" alt="Risky Jobs" style="float:right" /> <h3>Risky Jobs - Search Results</h3> <?php // 1,5,10 // Filename:C:,HeadFirst_PHP_MYSQL,Chapter9, // riskyjobs_riskybusiness_Database_TableSetup_riskyjobs_Table_Chapter9_Page546_search_final.php // This function builds a search query from the search keywords and sort setting function build_query($user_search, $sort) { $search_query = "SELECT * FROM riskyjobs"; // Extract the search keywords into an array $clean_search = str_replace(',', ' ', $user_search); $search_words = explode(' ', $clean_search); $final_search_words = array(); if (count($search_words) > 0) { foreach ($search_words as $word) { if (!empty($word)) { $final_search_words[] = $word; } } } // Generate a WHERE clause using all of the search keywords $where_list = array(); if (count($final_search_words) > 0) { foreach($final_search_words as $word) { $where_list[] = "description LIKE '%$word%'"; } } $where_clause = implode(' OR ', $where_list); // Add the keyword WHERE clause to the search query if (!empty($where_clause)) { $search_query .= " WHERE $where_clause"; } // Sort the search query using the sort setting switch ($sort) { // Ascending by job title case 1: $search_query .= " ORDER BY title"; break; // Descending by job title case 2: $search_query .= " ORDER BY title DESC"; break; // Ascending by state case 3: $search_query .= " ORDER BY state"; break; // Descending by state case 4: $search_query .= " ORDER BY state DESC"; break; // Ascending by date posted (oldest first) case 5: $search_query .= " ORDER BY date_posted"; break; // Descending by date posted (newest first) case 6: $search_query .= " ORDER BY date_posted DESC"; break; default: // No sort setting provided, so don't sort the query } return $search_query; } // INTERIM INTERIM INTERIM INTERIM // This function builds heading links based on the specified sort setting function generate_sort_links($user_search, $sort) { $sort_links = ''; switch ($sort) { case 1: $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=2">Job Title</a></td><td>Description</td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=3">State</a></td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=5">Date Posted</a></td>'; break; case 3: $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=1">Job Title</a></td><td>Description</td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=4">State</a></td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=5">Date Posted</a></td>'; break; case 5: $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=1">Job Title</a></td><td>Description</td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=3">State</a></td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=6">Date Posted</a></td>'; break; default: $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=1">Job Title</a></td><td>Description</td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=3">State</a></td>'; $sort_links .= '<td><a href = "' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=5">Date Posted</a></td>'; } return $sort_links; } // NEW STUFF PART 1 NEW STUFF PART 1 // Grab the sort setting and search keywords from the URL using GET $sort = $_GET['sort']; $user_search = $_GET['usersearch']; // Start generating the table of results echo '<table border="0" cellpadding="2">'; // Generate the search result headings echo '<tr class="heading">'; echo generate_sort_links($user_search, $sort); echo '</tr>'; // Connect to the database require_once('riskyjobs_riskybusiness_Database_TableSetup_riskyjobs_Table_Chapter9_Page546_connectvars_final.php'); $dbc = mysqli_connect('PRIVATE', 'PRIVATE', 'PRIVATE', 'PRIVATE'); // Query to get the total results $query = build_query($user_search, $sort); $result = mysqli_query($dbc, $query); // NEW STUFF PART 2 NEW STUFF PART 2 while ($row = mysqli_fetch_array($result)) { echo '<tr class="results">'; echo '<td valign="top" width="20%">' . $row['title'] . '</td>'; // changed $row['description'] . ' in the next line to substr($row['description'],0,100) . ' ... // on 12,31,09 echo '<td valign="top" width="50%">' . substr($row['description'],0,100) . ' ...</td>'; echo '<td valign="top" width="10%">' . $row['state'] . '</td>'; // changed $row['date_posted'] in the next line to substr($row['date_posted'],0,10) // on 12,31,09 echo '<td valign="top" width="20%">' . substr($row['date_posted'],0,10) . '</td>'; echo '</tr>'; } echo '</table>'; mysqli_close($dbc); ?> </body> </html> I would appreciate the help!!!
-
Hello: I'm having a problem with my PHP code. I receive the following two error messages when I try to run the code: Warning: mysqli_query() [function.mysqli-query]: Empty query in /home/content/PRIVATE/html/riskyjobs_riskybusiness_Database_TableSetup_riskyjobs_Table_Chapter9_Page539_search_final.php on line 108 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/content/PRIVATE/html/riskyjobs_riskybusiness_Database_TableSetup_riskyjobs_Table_Chapter9_Page539_search_final.php on line 111 The code is as follows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Risky Jobs - Search</title> <link rel="stylesheet" type="text/css" href="style_Page539_final.css" /> </head> <body> <img src="riskyjobs_title.gif" alt="Risky Jobs" /> <img src="riskyjobs_fireman.jpg" alt="Risky Jobs" style="float:right" /> <h3>Risky Jobs - Search Results</h3> <?php // 12,30,09 // Filename:C:,HeadFirst_PHP_MYSQL,Chapter9, // riskyjobs_riskybusiness_Database_TableSetup_riskyjobs_Table_Chapter9_Page539_search_final.php // Grab the sort setting and search keywords from the URL using GET $sort = $_GET['sort']; $user_search = $_GET['usersearch']; // Start generating the table of results echo '<table border="0" cellpadding="2">'; // Generate the search result headings echo '<tr class="heading">'; echo '<td>Job Title</td><td>Description</td><td>State</td><td>Date Posted</td>'; echo '</tr>'; // Connect to the database require_once('riskyjobs_riskybusiness_Database_TableSetup_riskyjobs_Table_Chapter9_Page539_connectvars_final.php'); $dbc = mysqli_connect('PRIVATE', 'PRIVATE', 'PRIVATE', 'PRIVATE'); // Query to get the results // Beginning of ADDED the following on 12,30,09 // Beginning of ADDED the following on 1,1,10 function build_query($user_search) { // End of ADDED the following on 1,1,10 $search_query = "SELECT * FROM riskyjobs"; // Extract the search keywords into an array $clean_search = str_replace(',', ' ', $user_search); $search_words = explode(' ', $clean_search); $final_search_words = array(); if (count($search_words) > 0) { foreach ($search_words as $word) { if (!empty($word)) { $final_search_words[] = $word; } } } // Generate a WHERE clause using all of the search keywords $where_list = array(); if (count($final_search_words) > 0) { foreach($final_search_words as $word) { $where_list[] = "description LIKE '%$word%'"; } } $where_clause = implode(' OR ', $where_list); // Add the keyword WHERE clause to the search query if (!empty($where_clause)) { $search_query .= " WHERE $where_clause"; } // End of ADDED the following on 12,30,09 // Beginning of ADDED the following on 1,1,10 return $search_query; } // End of ADDED the following on 1,1,10 $result = mysqli_query($dbc, $search_query); while ($row = mysqli_fetch_array($result)) { echo '<tr class="results">'; echo '<td valign="top" width="20%">' . $row['title'] . '</td>'; // changed $row['description'] . ' in the next line to substr($row['description'],0,100) . ' ... // on 12,31,09 echo '<td valign="top" width="50%">' . substr($row['description'],0,100) . ' ...</td>'; echo '<td valign="top" width="10%">' . $row['state'] . '</td>'; // changed $row['date_posted'] in the next line to substr($row['date_posted'],0,10) // on 12,31,09 echo '<td valign="top" width="20%">' . substr($row['date_posted'],0,10) . '</td>'; echo '</tr>'; } echo '</table>'; mysqli_close($dbc); ?> </body> </html> I would appreciate your help!!!
-
Hello: I'm a newbie to PHP and MySQL and have a problem with one of my files on my Website. It was working properly before I started to condense the coding using JOINS, etc. Please note that for my naming of the Tables: mismatch_topic = peach mismatch_response = leach mismatch_user = Beach mismatch_category = keach I am able to login to the mismatch Website that I created, however when I click on the questionnaire, I receive the following error message: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/content/PRIVATE/html/questionnaire_Chapter8_Page457.php on line 138 I would appreciate the help!!! It's probably not necessary to list all of the files that are on my Website, so I am listing only the file that I think is causing the problems. <? ob_start(); ?> <?php // Filename: C:,questionnaire_Chapter8_Page481.php // Start the session require_once('startsession_Chapter8_Page457.php'); // Insert the page header $page_title = 'Questionnaire'; require_once('header_Chapter8_Page457.php'); require_once('appvars_Chapter8_Page457.php'); require_once('connectvars_Chapter8_Page457.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<p class="login">Please <a href="login_Chapter8_Page457.php">log in</a> to access this page.</p>'; exit(); } // Show the navigation menu require_once('navmenu_Chapter8_Page457.php'); // Connect to the database $dbc = mysqli_connect('PRIVATE', 'PRIVATE', 'PRIVATE', 'PRIVATE'); // If this user has never answered the questionnaire, insert empty responses into the database // changed mismatch_response to leach on 11,18,09 $query = "SELECT * FROM leach WHERE user_id = '" . $_SESSION['user_id'] . "'"; $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 0) { // First grab the list of topic IDs from the topic table //changed category_id to category per the errata on 11\10\09 // changed mismatch_topic to peach on 11,18,09 $query = "SELECT topic_id FROM peach ORDER BY category, topic_id"; $data = mysqli_query($dbc, $query); $topicIDs = array(); while ($row = mysqli_fetch_array($data)) { array_push($topicIDs, $row['topic_id']); } // Insert empty response rows into the response table, one per topic foreach ($topicIDs as $topic_id) { // changed mismatch_response to leach on 11,18,09 $query = "INSERT INTO leach (user_id, topic_id) VALUES ('" . $_SESSION['user_id']. "', '$topic_id')"; mysqli_query($dbc, $query); } } // If the questionnaire form has been submitted, write the form responses to the database if (isset($_POST['submit'])) { // Write the questionnaire response rows to the response table foreach ($_POST as $response_id => $response) { // changed mismatch_response to leach on 11,18,09 $query = "UPDATE leach SET response = '$response' WHERE response_id = '$response_id'"; mysqli_query($dbc, $query); } echo '<p>Your responses have been saved.</p>'; } // Grab the response data from the database to generate the form // changed mismatch_response to leach on 11,18,09 // BEGINNING of insert on 12,15,09 // This coding was inserted for Chapter 8, page 480 // First grab the user's responses from the response table (JOIN to get the topic name) $query = "SELECT mr.response_id, mr.topic_id, mr.response," . "mt.name AS topic_name, mc.name AS category_name" . "FROM leach AS mr" . "INNER JOIN peach AS mt USING (topic_id) " . "INNER JOIN keach AS mc USING (category_id) " . "WHERE mr.user_id = '" . $_SESSION['user_id'] . "'"; $data = mysqli_query($dbc, $query); $responses = array(); while ($row = mysqli_fetch_array($data)) { array_push($user_responses, $row); } // END of insert on 12,15,09 mysqli_close($dbc); // Generate the questionnaire form by looping through the response array echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">'; echo '<p>How do you feel about each topic?</p>'; $category = $responses[0]['category_name']; echo '<fieldset><legend>' . $responses[0]['category_name'] . '</legend>'; foreach ($responses as $response) { // Only start a new fieldset if the category has changed if ($category != $response['category_name']) { $category = $response['category_name']; echo '</fieldset><fieldset><legend>' . $response['category_name'] . '</legend>'; } // Display the topic form field echo '<label ' . ($response['response'] == NULL ? 'class="error"' : '') . ' for="' . $response['response_id'] . '">' . $response['topic_name'] . ':</label>'; echo '<input type="radio" id="' . $response['response_id'] . '" name="' . $response['response_id'] . '" value="1" ' . ($response['response'] == 1 ? 'checked="checked"' : '') . ' />Love '; echo '<input type="radio" id="' . $response['response_id'] . '" name="' . $response['response_id'] . '" value="2" ' . ($response['response'] == 2 ? 'checked="checked"' : '') . ' />Hate<br />'; } echo '</fieldset>'; echo '<input type="submit" value="Save Questionnaire" name="submit" />'; echo '</form>'; // Insert the page footer require_once('footer_Chapter8_Page457.php'); ?> <? ob_flush(); ?>