Jump to content
Larry Ullman's Book Forums

Stx

Members
  • Posts

    13
  • Joined

  • Last visited

Stx's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. So even though I was able to resolve that issue, I notice that the image is not getting stored in the data base and as a result it not showing up on the site either. So the price, description show but the image is not showing up. The image is in the product folder but not outputting on the site. Can anyone help with that issue?
  2. So after doing a little further inquiries I was able to resolve the matter. I did not have a product folder in my admin sub-directory as a result the product image was not be store anywhere. Also bear in mind if you are using a sub-directory make sure your $dest = "./products/$new_name"; that is line 85 is properly positioned within your file system otherwise you will be experiencing the same problem as I did in the above.
  3. 1) Hi there, I was experiencing the exact same problem and did the changes recommended above, however I am getting the following message when I attempt to upload a product. The message is as follow: ======================================================== 2) An error occurred in script '/home/content/82/11778682/html/admin/add_other_products.php' on line 87: move_uploaded_file(../products/276edc67b6955cf76faf19df99dc856ffb2ed121. ) [function.move-uploaded-file]: failed to open stream: No such file or directory Array ======================================================== 3) Can anyone point out where it is I am going wrong your help would be much appreciated to me and fellow forum members.
  4. I am also running into the same problem the difference however, is that am running mine on a live server. So my error is as follow: An error occurred in script '/home/content/82/11778682/html/shop/views/home.html' on line 9: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given This is what line 9 actually looks like: // If records are returned, include the view: if (mysqli_num_rows($r) > 0) { echo '<dl class="special fright"> <dt><a href="/shop/sales/">Sale Items</a></dt>'; // Fetch each item: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<dd><a href="/shop/sales/#' . $row['sku'] . '" title="View This Product"><img alt="" src="/products/' . $row['image'] . '" /><span>' . $row['sale_price'] . '</span></a></dd>'; } echo '</dl>'; I would really appreciate it if you can help me resolve this issue.
  5. For the past several days, I have been following virtually everything from the add_php.php file but for some reason nothing is being sent to the data base. I am getting the following message: A system error occurred. We apologize for the inconvenience. That is occoring on line 74, 85, 116, 117, 141 and 142. I would really appreciate it if a member can clarifiy to me why this is not working and what steps needed to make it work. here are the affected areas. I have highlighted them in red so you could see in the following: if (move_uploaded_file($file['tmp_name'], $dest)) { // Store the data in the session for later use: $_SESSION['pdf']['tmp_name'] = $tmp_name; $_SESSION['pdf']['size'] = $size; $_SESSION['pdf']['file_name'] = $file['name']; // Print a message: echo '<div class="alert alert-success"><h3>The file has been uploaded!</h3></div>'; } else { trigger_error('The file could not be moved.'); unlink ($file['tmp_name']); } } // End of array_key_exists() IF. } elseif (!isset($_SESSION['pdf'])) { // No current or previous uploaded file. switch ($_FILES['pdf']['error']) { case 1: case 2: $add_pdf_errors['pdf'] = 'The uploaded file was too large.'; break; case 3: $add_pdf_errors['pdf'] = 'The file was only partially uploaded.'; break; case 6: case 7: case 8: $add_pdf_errors['pdf'] = 'The file could not be uploaded due to a system error.'; break; case 4: default: $add_pdf_errors['pdf'] = 'No file was uploaded.'; break; } // End of SWITCH. } // End of $_FILES IF-ELSEIF-ELSE. if (empty($add_pdf_errors)) { // If everything's OK. // Add the PDF to the database: $fn = escape_data($_SESSION['pdf']['file_name'], $dbc); $tmp_name = escape_data($_SESSION['pdf']['tmp_name'], $dbc); $size = (int) $_SESSION['pdf']['size']; $q = "INSERT INTO pdfs (title, description, tmp_name, file_name, size) VALUES ('$t', '$d', '$tmp_name', '$fn', $size)"; $r = mysqli_query($dbc, $q); if (mysqli_affected_rows($dbc) === 1) { // If it ran OK. // Rename the temporary file: $original = PDFS_DIR . $tmp_name . '_tmp'; $dest = PDFS_DIR . $tmp_name; rename($original, $dest); // Print a message: echo '<div class="alert alert-success"><h3>The PDF has been added!</h3></div>'; // Clear $_POST: $_POST = array(); // Clear $_FILES: $_FILES = array(); // Clear $file and $_SESSION['pdf']: unset($file, $_SESSION['pdf']); } else { // If it did not run OK. trigger_error('The PDF could not be added due to a system error. We apologize for any inconvenience.'); unlink ($dest); }
  6. I am also experiencing a slightly different problem with the add_page.php file. For some reason, when I attempt to submit a page it's issusing me the following statement Please select a category! The problem is there are no categories to select other that the word select. So essencially, nothing is getting submitted to my data base and I have attempt to seach the code for any problem without any success. Here is what my code currently looks like: // This page is used by an administrator to create a specific page of HTML content. // This script is created in Chapter 5. // Require the configuration before any PHP code as the configuration controls error reporting: require('./includes/config.inc.php'); // If the user isn't logged in as an administrator, redirect them: redirect_invalid_user('user_admin'); // Require the database connection: require('./includes/mysql.inc.php'); // Include the header file: $page_title = 'Add a Site Content Page'; include('./includes/header.html'); // For storing errors: $add_page_errors = array(); // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Check for a title: if (!empty($_POST['title'])) { $t = escape_data(strip_tags($_POST['title']), $dbc); } else { $add_page_errors['title'] = 'Please enter the title!'; } // Check for a category: if (filter_var($_POST['category'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $cat = $_POST['category']; } else { // No category selected. $add_page_errors['category'] = 'Please select a category!'; } // Check for a description: if (!empty($_POST['description'])) { $d = escape_data(strip_tags($_POST['description']), $dbc); } else { $add_page_errors['description'] = 'Please enter the description!'; } // Check for the content: if (!empty($_POST['content'])) { $allowed = '<div><p><span><br><a><img><h1><h2><h3><h4><ul><ol><li><blockquote>'; $c = escape_data(strip_tags($_POST['content'], $allowed), $dbc); } else { $add_page_errors['content'] = 'Please enter the content!'; } if (empty($add_page_errors)) { // If everything's OK. // Add the page to the database: $q = "INSERT INTO pages (categories_id, title, description, content) VALUES ($cat, '$t', '$d', '$c')"; $r = mysqli_query($dbc, $q); if (mysqli_affected_rows($dbc) === 1) { // If it ran OK. // Print a message: echo '<div class="alert alert-success"><h3>The page has been added!</h3></div>'; // Clear $_POST: $_POST = array(); // Send an email to the administrator to let them know new content was added? } else { // If it did not run OK. trigger_error('The page could not be added due to a system error. We apologize for any inconvenience.'); } } // End of $add_page_errors IF. } // End of the main form submission conditional. // Need the form functions script, which defines create_form_input(): require('includes/form_functions.inc.php'); ?> <h1>Add a Site Content Page</h1> <form action="add_page.php" method="post" accept-charset="utf-8"> <fieldset><legend>Fill out the form to add a page of content:</legend> <div class="form-group"> <label for="status" class="control-label">Status</label> <select name="status" class="form-control"><option value="draft">Draft</option> <option value="live">Live</option> </select></div> <?php create_form_input('title', 'text', 'Title', $add_page_errors); // Add the category drop down menu: echo '<div class="form-group'; if (array_key_exists('category', $add_page_errors)) echo ' has-error'; echo '"><label for="category" class="control-label">Category</label> <select name="category" class="form-control"> <option>Select One</option>'; // Bonus material! // Added in Chapter 12. // Allow for multiple categories: echo '"><label for="category" class="control-label">Category</label> <select name="category[]" class="form-control" multiple size="5">'; // Retrieve all the categories and add to the pull-down menu: $q = "SELECT id, category FROM categories ORDER BY category ASC"; $r = mysqli_query($dbc, $q); while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['category']) && ($_POST['category'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } echo '</select>'; if (array_key_exists('category', $add_page_errors)) echo '<span class="help-block">' . $add_page_errors['category'] . '</span>'; echo '</div>'; create_form_input('description', 'textarea', 'Description', $add_page_errors); create_form_input('content', 'textarea', 'Content', $add_page_errors); ?> <input type="submit" name="submit_button" value="Add This Page" id="submit_button" class="btn btn-default" /> </fieldset> </form> <script type="text/javascript" src="js/tinymce/tinymce.min.js"></script> <script type="text/javascript"> tinyMCE.init({ // General options selector : "#content", width : 800, height : 400, browser_spellcheck : true, plugins: "paste,searchreplace,fullscreen,hr,link,anchor,image,charmap,media,autoresize,autosave,contextmenu,wordcount", toolbar1: "cut,copy,paste,|,undo,redo,removeformat,|hr,|,link,unlink,anchor,image,|,charmap,media,|,search,replace,|,fullscreen", toolbar2: "bold,italic,underline,strikethrough,|,alignleft,aligncenter,alignright,alignjustify,|,formatselect,|,bullist,numlist,|,outdent,indent,blockquote,", // Example content CSS (should be your site CSS) content_css : "/html/css/bootstrap.min.css", }); </script> <!-- /TinyMCE --> <?php /* PAGE CONTENT ENDS HERE! */ // Include the footer file to complete the template: include('./includes/footer.html'); ?> I would greatly appreciate it if a member can point to me where it is I am going wrong. Thanks.
  7. So I was able to solve one of the problem. My Account table is working along with the dropdown menu however, the Admin is not showing up on the menu bar. So if anyone can share a solution I would greatly appreciate it. cheers.
  8. I am also encountering some problem with getting my dropdown to work. Infact, it the <li> in the the dropedown under Account is not showing up and my Admin tab is not showing up. As suggested in the above, I have downloaded the bootstrap.min.js file and place it in the js folder and I am following the book instructions as best as I can without any success. Is there anyway someone can discern where it is am going wrong. Your help would greatly be appreciated. My code in the head.html is as follow: =================================================================================================== <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content=""> <title><?php // Use a default page title if one wasn\'t'\ provided... if (isset($page_title)) { echo $page_title; } else { echo 'C-PARK'; } ?></title> <!-- Bootstrap core CSS --> <link href="css/bootstrap.min.css" rel="stylesheet"> <!-- Custom styles for this template --> <link href="css/sticky-footer-navbar.css" rel="stylesheet"> </head> <body> <!-- Wrap all page content here --> <div id="wrap"> <!-- Fixed navbar --> <div class="navbar navbar-fixed-top"> <div class="container"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="index.php">CENTENNIAL PARK</a> <div class="nav-collapse collapse"> <ul class="nav navbar-nav"> <?php // Dynamically create header menus... // Array of labels and pages (without extensions): $pages = array ( 'Home' => 'index.php', 'About' => '#', 'Contact' => '#', 'Register' => 'register.php' ); // The page being viewed: $this_page = basename($_SERVER['PHP_SELF']); // Create each menu item: foreach ($pages as $k => $v) { // Start the item: echo '<li'; // Add the class if it's the current page: if ($this_page == $v) echo ' class="active"'; // Complete the item: echo '><a href="' . $v . '">' . $k . '</a></li> '; } // End of FOREACH loop. // Show the user options: if (isset($_SESSION['user_id'])) { // Show basic user options: // Includes references to some bonus material discussed in Part Four! echo '<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Account <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="logout.php">Logout</a></li> <li><a href="renew.php">Renew</a></li> <li><a href="change_password.php">Change Password</a></li> <li><a href="favorites.php">Favorites</a></li> <li><a href="recommendations.php">Recommendations</a></li> </ul> </li>'; // Show admin options, if appropriate: if (isset($_SESSION['user_admin'])) { echo '<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="add_page.php">Add Page</a></li> <li><a href="add_pdf.php">Add PDF</a></li> <li><a href="#">Something else here</a></li> </ul> </li>'; } } // user_id not set. ?> </ul> </div><!--/.nav-collapse --> </div><!--/container--> </div><!--/navbar--> <!-- Begin page content --> <div class="container"> <div class="row"> <div class="col-3"> <h3 class="text-success">Content</h3> <div class="list-group"> <?php // Dynamically generate the content links: $q = 'SELECT * FROM categories ORDER BY category'; $r = mysqli_query($dbc, $q); while (list($id, $category) = mysqli_fetch_array($r, MYSQLI_NUM)) { echo '<a href="category.php?id=' . $id . '" class="list-group-item" title="' . $category . '">' . htmlspecialchars($category) . ' </a>'; } ?> <!-- <a href="pdfs.php" class="list-group-item" title="PDFs">PDF Guides </a>--> <a href="pdfs.php" class="list-group-item" title="PDFs">Olympum </a> <a href="pdfs.php" class="list-group-item" title="PDFs">Stadium </a> <a href="pdfs.php" class="list-group-item" title="PDFs">Chalet </a> <a href="pdfs.php" class="list-group-item" title="PDFs">Playing Fields </a> <a href="pdfs.php" class="list-group-item" title="PDFs">Golf </a> <a href="pdfs.php" class="list-group-item" title="PDFs">Green House </a> <a href="pdfs.php" class="list-group-item" title="PDFs">Pinic Areas </a> <a href="pdfs.php" class="list-group-item" title="PDFs">Go Kart </a> <a href="pdfs.php" class="list-group-item" title="PDFs">Wading Pool </a> </div><!--/list-group--> <?php // Should we show the login form? if (!isset($_SESSION['user_id'])) { require('includes/login_form.inc.php'); } ?> </div><!--/col-3--> <div class="col-9"> <!-- CONTENT -->
  9. Here are how my final codes looks like: <?php // This is the registration page for the site. // This file both displays and processes the registration form. // This script is begun in Chapter 4. // Require the configuration before any PHP code as the configuration controls error reporting: require('./includes/config.inc.php'); // The config file also starts the session. // Require the database connection: require('./includes/mysql.inc.php'); // Include the header file: $page_title = 'Register'; include('./includes/header.html'); // For storing registration errors: $reg_errors = array(); // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Check for a first name: if (preg_match('/^[A-Z \'.-]{2,45}$/i', $_POST['first_name'])) { $fn = escape_data($_POST['first_name'], $dbc); } else { $reg_errors['first_name'] = 'Please enter your first name!'; } // Check for a last name: if (preg_match('/^[A-Z \'.-]{2,45}$/i', $_POST['last_name'])) { $ln = escape_data($_POST['last_name'], $dbc); } else { $reg_errors['last_name'] = 'Please enter your last name!'; } // Check for a username: if (preg_match('/^[A-Z0-9]{2,45}$/i', $_POST['username'])) { $u = escape_data($_POST['username'], $dbc); } else { $reg_errors['username'] = 'Please enter a desired name using only letters and numbers!'; } // Check for an email address: if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === $_POST['email']) { $e = escape_data($_POST['email'], $dbc); } else { $reg_errors['email'] = 'Please enter a valid email address!'; } // Check for a password and match against the confirmed password: if (preg_match('/^(\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*){6,}$/', $_POST['pass1']) ) { if ($_POST['pass1'] === $_POST['pass2']) { $p = $_POST['pass1']; } else { $reg_errors['pass2'] = 'Your password did not match the confirmed password!'; } } else { $reg_errors['pass1'] = 'Please enter a valid password!'; } if (empty($reg_errors)) { // If everything's OK... // Make sure the email address and username are available: $q = "SELECT email, username FROM users WHERE email='$e' OR username='$u'"; $r = mysqli_query($dbc, $q); // Get the number of rows returned: $rows = mysqli_num_rows($r); if ($rows === 0) { // No problems! // Add the user to the database... // Include the password_compat library, if necessary: include('./includes/lib/password.php'); // Temporary: set expiration to a month! // Change after adding PayPal! $q = "INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('$u', '$e', '" . password_hash($p, PASSWORD_BCRYPT) . "', '$fn', '$ln', ADDDATE(NOW(), INTERVAL 1 MONTH) )"; // New query, updated in Chapter 6 for PayPal integration: // Sets expiration to yesterday: // $q = "INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('$u', '$e', '" . password_hash($p, PASSWORD_BCRYPT) . "', '$fn', '$ln', SUBDATE(NOW(), INTERVAL 1 DAY) )"; $r = mysqli_query($dbc, $q); if (mysqli_affected_rows($dbc) === 1) { // If it ran OK. // Get the user ID: // Store the new user ID in the session: // Added in Chapter 6: $uid = mysqli_insert_id($dbc); // $_SESSION['reg_user_id'] = $uid; // Display a thanks message... // Original message from Chapter 4: // echo '<div class="alert alert-success"><h3>Thanks!</h3><p>Thank you for registering! You may now log in and access the site\'s content.</p></div>'; // Updated message in Chapter 6: echo '<div class="alert alert-success"><h3>Thanks!</h3><p>Thank you for registering! To complete the process, please now click the button below so that you may pay for your site access via PayPal. The cost is $10 (US) per year. <strong>Note: When you complete your payment at PayPal, please click the button to return to this site.</strong></p></div>'; // PayPal link added in Chapter 6: echo '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="email" value="' . $e . '"> <input type="hidden" name="hosted_button_id" value="8YW8FZDELF296"> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> '; // Send a separate email? $body = "Thank you for registering at <whatever site>. Blah. Blah. Blah.\n\n"; mail($_POST['email'], 'Registration Confirmation', $body, 'From: admin@example.com'); // Finish the page: include('./includes/footer.html'); // Include the HTML footer. exit(); // Stop the page. } else { // If it did not run OK. trigger_error('You could not be registered due to a system error. We apologize for any inconvenience. We will correct the error ASAP.'); } } else { // The email address or username is not available. if ($rows === 2) { // Both are taken. $reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at left to have your password sent to you.'; $reg_errors['username'] = 'This username has already been registered. Please try another.'; } else { // One or both may be taken. // Get row: $row = mysqli_fetch_array($r, MYSQLI_NUM); if( ($row[0] === $_POST['email']) && ($row[1] === $_POST['username'])) { // Both match. $reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at left to have your password sent to you.'; $reg_errors['username'] = 'This username has already been registered with this email address. If you have forgotten your password, use the link at left to have your password sent to you.'; } elseif ($row[0] === $_POST['email']) { // Email match. $reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, use the link at left to have your password sent to you.'; } elseif ($row[1] === $_POST['username']) { // Username match. $reg_errors['username'] = 'This username has already been registered. Please try another.'; } } // End of $rows === 2 ELSE. } // End of $rows === 0 IF. } // End of empty($reg_errors) IF. } // End of the main form submission conditional. // Need the form functions script, which defines create_form_input(): // The file may already have been included by the header. require_once('./includes/form_functions.inc.php'); ?><h1>Register</h1> <p>Access to the site's content is available to registered users at a cost of $10.00 (US) per year. Use the form below to begin the registration process. <strong>Note: All fields are required.</strong> After completing this form, you'll be presented with the opportunity to securely pay for your yearly subscription via <a href="http://www.paypal.com">PayPal</a>.</p> <form action="register.php" method="post" accept-charset="utf-8"> <?php create_form_input('first_name', 'text', 'First Name', $reg_errors); create_form_input('last_name', 'text', 'Last Name', $reg_errors); create_form_input('username', 'text', 'Desired Username', $reg_errors); echo '<span class="help-block">Only letters and numbers are allowed.</span>'; create_form_input('email', 'email', 'Email Address', $reg_errors); create_form_input('pass1', 'password', 'Password', $reg_errors); echo '<span class="help-block">Must be at least 6 characters long, with at least one lowercase letter, one uppercase letter, and one number.</span>'; create_form_input('pass2', 'password', 'Confirm Password', $reg_errors); ?> <input type="submit" name="submit_button" value="Next →" id="submit_button" class="btn btn-default" /> </form> <br> <?php // Include the HTML footer: include('./includes/footer.html'); ?>
  10. Thanks Larry. I followed your previous recommendation and it seem to be working now. The problem is initially, I did not add the lib folder consisting of the password.php file in the includes folder. Because I am using godaddy server, I thought they were running the latest php. However, when I checked, my version was lower so I just need to download the file and add it into my includes folder and now it's worked like a charm. So for anyone encountering a similar problem ensure that you are running the correct php version otherwise do exactly as Larry recommends in the book and it should work. Again thanks. Cheers.
  11. Thank you Larry for your quick response. I have attempted everything conceivable to resolve the issue and unfortunately, I have not been able to get it right. Am not too sure what function that is hinder my progress. Very frustrating cause it's been quite sometime I have been dealing with this issue. If you are able to provide further insight, I along with others would greatly benefit from it a clearer explanation. Thanks .
  12. I too would like to see the step by step solution to this problem because when I attempt to register, I get the following Fatal Error: Fatal error: Call to undefined function password_hash() in /home/content/82/11778682/html/html/register.php on line 86 The codes on line 86 is as follow: $q = "INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('$u', '$e', '" . password_hash($p, PASSWORD_BCRYPT) . "', '$fn', '$ln', SUBDATE(NOW(), INTERVAL 1 DAY) )"; I would really appreciate it if some can indicate to me what it is am over looking here. cheers Thanks.
  13. Hi there, I too fine this book to be totally awesome. I am completely new to php and the approach you took in writing this book demystify this scripting language. I am stuck on chapter 8 with the topic "USING EXTERNAL FILES". I followed everything that was suggested in creating the template however when I run index.php all I see is the php script in the browser. I am local host server. Can you please advise how to resolve this issue cause it is quite daunting. Thanks cheers.
×
×
  • Create New...