Jump to content
Larry Ullman's Book Forums

Chris-M

Members
  • Posts

    12
  • Joined

  • Last visited

Chris-M's Achievements

Newbie

Newbie (1/14)

1

Reputation

  1. Larry, I think I tried putting the show_images script in different places to see if it would work, it is now back in htdocs, and is now working - although it didn't initially. When it didn't work I re-read the chapter and checked the scripts, but didn't think I had found any errors, reloaded the scripts and all seems to be working well. Only wish I knew what sript errors I had corrected.
  2. That may be the case, but I can't see the error yet. I must have the correct path and URL for script 104 (images) to work. I can apply script 105 to look at a sub folder of 'htdocs' i.e. 'url/images' but not to one that is adjacent to htdocs, in this case 'uploads'. see http://www.chris-muten.com/Images104.php for a list of images in 'uploads', for which script 105 doesn't quite work. and http://www.chris-muten.com/Images104c.php for a list of images in www.chris-muten.com/Images for which script 105 works well. A screen shot of the uploads directory can be seen at http://www.chris-muten.com/Images/show_image105c.php?image=uploads.jpg (I tried to add this image here as png then jpg but in both cases the following error message appeared: "You are not allowed to use that image extension on this community.").
  3. I was having problems with script 10.5. I thought it may be due to the folder permission for the 'uploads' folder, so I tried it on a folder called Images in the htdocs folder. This I managed to get working. Applying this back the script trying to access the 'uploads' folder still didn't overcome the problem. Script 10.4 works as it lists the images in the 'uploads' folder. However, when I click on a link in the table generated by script 10.4, I get a pop up window with error 404 - File or directory not found. I tried to view the images in the uploads folder without script 10.5, by: 'URL'/..uploads/image_name.jpg But had the same result, although 'URL'/Images/image_name.jpg worked fine (In both cases the image_name was valid). Why can I create a list of images, yet not be able to view them from that list? Thanks in advance.
  4. HartleySan, Thanks, I added the code, when the line without '&p=' . $pages . is used I get: Array ( => 10 [sort] => rd ) and no errors. Whereas when using the line with '&p=' . $pages . I get Array ( => 5 [p] => 3 [sort] => rd ) and the error report 'Undefined variable: records' the script has the line: $records = $row[0]; but I've just realised this line only runs if p has not been defined. So to overcome this I'e added the following script: // Determine how many records there are.. if(isset($_GET['r']) && is_numeric($_GET['r'])) { //Already been determined $records = $_GET['r']; } else { // need to determine // count the number of records $q = "SELECT COUNT(user_id) FROM users"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; } and this works OK. Having now seen the coding error it looks like a silly one, but the result was annoying. At least I've got to grips with the error reporting, Which would have taken longer without your prompts. Many thanks for you help, and this great forum.
  5. HartleySan, The URL script: echo '<a href="view_users.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort .'">Previous</a> '; is the one that gives the error, - generating the url: /view_users.php?s=0&p=3&sort=ct where as: echo '<a href="veiw_users.php?s=' . ($start - $display) . '&sort=' . $sort .'">Previous</a> '; works fine, the URL generated: view_users.php?s=0&sort=ct - is this what you were wanting to see?
  6. Emilie, Thanks - I've found the 'code' tags icon you mentioned, will try to remember for next time! HartleySan, Thanks. Removing the '&p=' . $pages . section of the URL line stopped the errors with no apparent side effects. I enabled error reporting (by including script 7.3 in my code), and the script ran fine with '&p=' . $pages . in the URL line - only this time I had the error meassge below the pagination line, and below that I had Users = . , instead of Users = 11. I can't figure out what '&p=' . $pages . adds to the code, apart from, in my case, an error which seems to delete that value in $records. Chris
  7. Emilie, Many thanks. Although the only way I could get the code to work now was to remove the '&p=' . $pages . part of the URL lines, as with that included I had '500 - Internal Server Error' when trying to navigate by pages. Although the code seems to work fine without this part. Chris
  8. Hi, I am having problems with pagination. I thought I had script 9.4 working without any problems, so carried on with script 9.5, which I also thought was working OK. I then added another table to my online database which I accessed by a script based on 9.5, but then I found the pagination wasn't working. I then found the pagination in script 9.5 wasn't working. The s and p appear in the url address line, and it would appear the code: if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } is ignored, as start always stays at 0 (or whatever value I put as $start = ). I've checked and double checked but can't see where the problem is. The full code is included here: ------------------------------------- <?php # Script 9.5 - view_users95.php // This script retrieves all the records from the users table. // This version allows the results to be sorted in different ways. // This version paginates the query results. $page_title = 'View the Current Users'; include ('includes/header8.html'); // Page header: echo '<h1>Registered Users 5</h1>'; require_once ('../mysqli_connect.php'); // Connect to the db. // Number of records to show per page: $display = 5; // Determine how many pages there are.. if(isset($_GET['p']) && is_numeric($_GET['p'])) { //Already been determined $pages = $_GET['p']; } else { // need to determine // count the number of records $q = "SELECT COUNT(user_id) FROM users"; $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 = 2; } }// end of p IF // Determine where in the database to start returning results if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Determine the sort... // Default is by registration date. $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'rd'; // Determine the sorting order: switch ($sort) { case 'ln': $order_by = 'last_name ASC'; break; case 'fn': $order_by = 'first_name ASC'; break; case 'rd': $order_by = 'registration_date ASC'; break; default: $order_by = 'registration_date ASC'; $sort = 'rd'; break; } // Make the query: $q = "SELECT last_name, first_name, DATE_FORMAT(registration_date, '%d %M, %Y') AS dr, user_id FROM users ORDER BY $order_by LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); // Run the query. // Table header. echo '<table border="5" align="center" cellspacing="0" cellpadding="5" width="50%"> <thead><tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b><a href="view_users95.php?sort=ln">Last Name</a></b></td> <td align="left"><b><a href="view_users95.php?sort=fn">First Name</a></b></td> <td align="left"><b><a href="view_users95.php?sort=rd">Date Registered</a></b></td> </tr> </thead>'; // Fetch and print all the records: $bg = '#eeeeee'; // Set the initial background colour. while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { //$bg = ($bg=='#bbbbbb' ? '#ffffff' : '#bbbbbb'); // Switch the background colour, using the Ternary operator. echo '<tr bgcolor="' . $bg . '"> <td align="left"><a href="edit_user93pw.php?id=' . $row['user_id'] . '">Edit</a></td> <td align="left"><a href="delete_user92pw.php?id=' . $row['user_id'] . '">Delete</a></td> <td align="left">' . $row['last_name'] . '</td> <td align="left">' . $row['first_name'] . '</td> <td align="left">' . $row['dr'] . '</td> </tr> '; } // end of while loop echo '</table>'; // Close the table. mysqli_free_result ($r); // Free up the resources. mysqli_close($dbc); // Close the database connection. //Make the links to other pages, if necessary if ($pages > 1) { // Add some spacing and start a paragraph echo '<br /><p>'; // Determine what page the script is on: $current_page = ($start/$display) + 1; // If it's not the first page, make a previous button: if ($current_page != 1) { echo '<a href="view_users95.php?s=' . ($start - $display) . ';p=' . $pages . ';sort=' . $sort .'">Previous</a> '; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="view_users95.php?s=' . (($display * ($i - 1))) . ';p=' . $pages . ';sort=' . $sort . '">' . $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="view_users95.php?s=' . ($start + $display) . ';p=' . $pages . ';sort=' . $sort . '">Next</a> '; } echo '</p>'; // close the paragraph } // end of the links section echo "<p>Users = $records.</p>\n"; // with this line in the pagination doesn't work echo "<p>Pages = $pages.</p>\n"; echo '<br />'; include ('includes/footerx.html'); ?> ----------------------------------- I hope you can shed some light on this problem Thanks Chris
  9. Hi, In chapter 10,script 10.3 Upload_Image. I get the message The file has been uploaded! even when I can't see the file in the 'uploads' folder I added to the website. If I replace ../uploads/ with ../htdocs/ in the script the image appears in the website 'htdocs' folder - great, at least the script is working as expected there. I can create folders alongside the htdocs one in my webspace but I can't change the properties of them - although they all seem to have the same (htdocs and uploads for example). My web host is Fasthosts. I see on the forum there have been similar questions, but with no conclusions. I suspect this is more of a web host issue than a php one, but it would be nice to know for sure and if there is a way round it. Thanks. Chris
  10. Larry, Many thanks, all working now with CHAR(40). Although I note the encoded password returned by: echo '<p>new encoded password is: ' . SHA1('$np') .'.</p>';; on my script is different to that listed in phpmyadmin (after refreshing once script 8.7 tells me the password has been updated). Maybe that is a quirk of phpmyadmin!
  11. Larry, Thanks, I broke down the conditionals: from: $q = "SELECT user_id FROM users WHERE (email='$e' AND pass=SHA1('$p') )"; to $q = "SELECT user_id FROM users WHERE (email='$e')"; and/ $q = "SELECT user_id FROM users WHERE (pass=SHA1('$p') )"; in turn. The script worked if I used only the email one, but if I included the password one it didn't find a match. I added a line to print the password and coded password on the screen. For password m1 the encoded password is: fc23764ac5b792f40bb1a00c0e3284e45f3f49c0 - 40 characters, but this is nothing like the 20 character one I see in phpmyadmin: 32d332da761f44df7959 for the same password. I can't see why I get 40 characters when the max length is set to 20 - although the maxlength is set prior to coding, should it still apply after the SHA1 coding? This difference explains why the conditional fails - but I can't see how to resolve this.
  12. I have downloaded script 8.7 from the LU web site and installed it on my web site as part of working through the book. However, every time I enter the correct information it keeps telling me the email and password do not match. I can't find any errata details for this or any listings on the Forum. Any ideas?
×
×
  • Create New...