Jump to content
Larry Ullman's Book Forums

armlocker

Members
  • Content Count

    83
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by armlocker

  1. I did indeed, just like this: define ('PDFS_DIR', './pdfs'); Error still occurs: An error occurred in script '/hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/add_pdf.php' on line 132: The PDF could not be added due to a system error. We apologize for any inconvenience. The corresponding error on line 132 in add_pdf.php is this: 128 // Clear $file and $_SESSION['pdf']: 129 unset($file, $_SESSION['pdf']); 130 131 } else { // If it did not run OK. 132 trigger_error('The PDF could not be added due to a system error. We apologize for any inconvenience.'); 133 unlink ($dest); 134 } 135 136 } // End of $errors IF.
  2. .... I have tried that constant: define ('PDFS_DIR', BASE_URI . './pdfs/'); but still getting this error message: An error occurred in script '/hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/add_pdf.php' on line 65: move_uploaded_file(/path/to/dir/./pdfs/df1bd4fbb72e4547143f5b1d4105ad4a83aec2e0_tmp) [function.move-uploaded-file]: failed to open stream: No such file or directory The line 65 oin add_pdf.php is referring to the config.inc.php constant shown above. But here is line 65 from add_pdf.php: 62 // Move the file to its proper folder but add _tmp, just in case: 63 $dest = PDFS_DIR . $tmp_name . '_tmp'; 64 65 if (move_uploaded_file($file['tmp_name'], $dest)) { 67 // Store the data in the session for later use: 68 $_SESSION['pdf']['tmp_name'] = $tmp_name; 69 $_SESSION['pdf']['size'] = $size; 70 $_SESSION['pdf']['file_name'] = $file['name']; =============================================================== (I have also made sure the directory permissions have been set to all changes in my web hosting server.)
  3. .... the 'pdfs' directory is in the web root directory .... and .... is in the same folder as 'add_pdf.php script' .... and .... I'm using a web hosting server ..... hope that helps (The server organisation is the same as Figure 3.3 on page 54)
  4. Hail Larry - 'The Jedi Master of php' I'm at a loss: I contacted the hosting server and been trying all manor of pathways to the the 'pdfs' folder situated on the server. Here's what I've tried, but still the same type of "...failed to open stream: No such file or directory ..." error message. (Interesting research about server directories in the meantime) Already tried, but did not work: define ('PDFS_DIR', BASE_URI . '/ftp.fatcow.com/21/wolfcut/pdfs/'); define ('PDFS_DIR', BASE_URI . '/ftp.fatcow.com/wolfcut/pdfs/'); define ('PDFS_DIR', '/ftp.fatcow.com/21/wolfcut/pdfs/'); define ('PDFS_DIR', '/ftp.fatcow.com/wolfcut/pdfs/'); define ('PDFS_DIR', BASE_URI . '/ftp.fatcow.com/laissezfairelondonco/PASSWORD/21/wolfcut/pdfs/'); define ('PDFS_DIR', BASE_URI . '/ftp.fatcow.com/laissezfairelondoncoPASSWORD/wolfcut/pdfs/'); define ('PDFS_DIR', '/ftp.fatcow.com/laissezfairelondonco/PASSWORD/21/wolfcut/pdfs/'); define ('PDFS_DIR', '/ftp.fatcow.com/laissezfairelondonco/PASSWORD/wolfcut/pdfs/'); define ('PDFS_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wolfcut/pdfs/'); define ('PDFS_DIR', $_SERVER['DOCUMENT_ROOT'] '/ftp.fatcow.com/wolfcut/pdfs/'); define ('PDFS_DIR', '/home/users/web/b1384/moo.laissezfairelondonco/wolfcut/pdfs/'); Error message in add_pdf.php An error occurred in script '/hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/add_pdf.php' on line 65: move_uploaded_file(pdfsa59c5ec29a76683da43ef9672987b848c5b6efd0wolfcut/pdfs_tmp) [function.move-uploaded-file]: failed to open stream: No such file or directory Line 65 of add_pdf.php if (move_uploaded_file($file['tmp_name'], $dest)) {
  5. ... things I have already tried which hasn't worked: define ('PDFS_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wolfcut/pdfs/'); define ('PDFS_DIR', BASE_URI . 'pdfs/');
  6. .... hiya Marg .... no frustration at all. I really enjoying this learning process .. AND ... this forum speak soon no doubt
  7. Hail All I have a problem with naming the location of the pdfs file in the config.inc.php file, which is preventing me from uploading pdfs: config.inc.php define ('BASE_URI', '/path/to/dir/'); define ('BASE_URL', 'www.wolfcut.co.uk/'); define ('PDFS_DIR', '/wolfcut/pdfs/'); define ('MYSQL', BASE_URI . 'mysql.inc.php'); root directory files on my web hosting server (fatcow) /wolfcut/pdfs/ and /wolfcut/includes/config.inc.php error message move_uploaded_file (/home/users/web/b1384/moo.laissezfairelondonco/wolfcut/wolfcut/pdfs/2 05c5187b34579c5cffbadd181853f3eea53d443_tmp) [function.move-uploaded-file]: failed to open stream: No such file or directory ============== Please help. I've almost finished the first project in Larry's book Many thanks
  8. ALL SORTED GUYS Yep , it was my mistake again (as usual). Here's the solution: SOLUTION: I didn't populate the database, hence why the Variable ['categories'] could not be found. All I had to do was copy the SQL commands from Larry's downloads and insert them into PHPMYADMIN. School Boy Error, but what a great learning experience. I now know the are 8 types of variable, what the are.... etc.... I know its not the conventional way of learning, but jumping in the deep end and tackling problems when the arise suits my style. Please continue to give me hints and tips as to where I go wrong. I can find out the rest and it makes things embed in my memory longer.
  9. Thanks Margaux, I have the book, but even that can be perplexing at times. Please take a look at the code from add_page.php: ============= <? require ('./includes/config.inc.php'); redirect_invalid_user('user_admin'); $page_title = 'Add a Site Content Page'; include ('./includes/header.html'); require ('./includes/mysql.inc.php'); $add_page_errors = array(); // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Check for a title: if (!empty($_POST['title'])) { $t = mysqli_real_escape_string($dbc, strip_tags($_POST['title'])); } else { $add_page_errors['title'] = 'Please enter the title!'; } // Check for a category: if (isset($_POST['category']) && (int) $_POST['category'] >= 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 = mysqli_real_escape_string($dbc, strip_tags($_POST['description'])); } 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 = mysqli_real_escape_string($dbc, strip_tags($_POST['content'], $allowed)); } else { $add_page_errors['content'] = 'Please enter the content!'; } if (empty($add_page_errors)) { $q = "INSERT INTO pages (category_id, title, description, content) VALUES ($cat, '$t', '$d', '$c')"; $r = mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. echo '<h4>The page has been added!</h4>'; // Clear $_POST: $_POST = array(); // Send an email to the administrator to let them know new content was added? } else { trigger_error('The page could not be added due to a system error. We apologize for any inconvenience.'); } } . } . require ('includes/form_functions.inc.php'); ?> <h3>Add a Site Content Page</h3> <form action="add_page.php" method="post" accept-charset="utf-8"> <fieldset><legend>Fill out the form to add a page of content:</legend> <p><label for="title"><strong>Title</strong></label><br /><?php create_form_input('title', 'text', $add_page_errors); ?></p> <p><label for="category"><strong>Category</strong></label><br /> <select name="category"<?php if (array_key_exists('category', $add_page_errors)) echo ' class="error"'; ?>> <option>Select One</option> <?php // 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"; } ?> </select><?php if (array_key_exists('category', $add_page_errors)) echo ' <span class="error">' . $add_page_errors['category'] . '</span>'; ?></p> <p><label for="description"><strong>Description</strong></label><br /><?php create_form_input('description', 'textarea', $add_page_errors); ?></p> <p><label for="content"><strong>Content</strong></label><br /><?php create_form_input('content', 'textarea', $add_page_errors); ?></p> <p><input type="submit" name="submit_button" value="Add This Page" id="submit_button" class="formbutton" /></p> </fieldset> </form> <script type="text/javascript" src="./tiny_mce/jscripts/tiny_mce.js"></script> <script type="text/javascript"> tinyMCE.init({ // General options mode : "exact", elements : "content", theme : "advanced", width : 800, height : 400, plugins : "advlink,advlist,autoresize,autosave,contextmenu,fullscreen,iespell,inlinepopups,media,paste,preview,safari,searchreplace,visualchars,wordcount,xhtmlxtras", // Theme options theme_advanced_buttons1 : "cut,copy,paste,pastetext,pasteword,|,undo,redo,removeformat,|,search,replace,|,cleanup,help,code,preview,visualaid,fullscreen", theme_advanced_buttons2 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,|,bullist,numlist,|,outdent,indent,blockquote,|,sub,sup,cite,abbr", theme_advanced_buttons3 : "hr,|,link,unlink,anchor,image,|,charmap,emotions,iespell,media", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : true, content_css : "./css/styles.css", }); </script> <!-- /TinyMCE --> <?php /* PAGE CONTENT ENDS HERE! */ include ('./includes/footer.html'); ?>
  10. The typo ')' you amended still leads to the same thing: "Please select a category!" Here's the complete error message: (its a long one).... ============ An error occurred in script '/hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/add_page.php' on line 34: Use of undefined constant var_dump - assumed 'var_dump' Array ( [0] => Array ( [file] => /hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/add_page.php [line] => 34 [function] => my_error_handler [args] => Array ( [0] => 8 [1] => Use of undefined constant var_dump - assumed 'var_dump' [2] => /hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/add_page.php [3] => 34 [4] => Array ( [GLOBALS] => Array *RECURSION* [_ENV] => Array ( [PATH] => /usr/local/bin:/usr/bin:/bin [sCRIPT_NAME] => /add_page.php [REQUEST_METHOD] => POST [HTTP_ACCEPT] => text/html, application/xhtml+xml, */* [sCRIPT_FILENAME] => /home/users/web/b1384/moo.laissezfairelondonco/wolfcut/add_page.php [sERVER_SOFTWARE] => Apache/2 [REMOTE_PORT] => 40734 [HTTP_USER_AGENT] => Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) [HTTP_CACHE_CONTROL] => no-cache [HTTP_ACCEPT_LANGUAGE] => en-GB [CONTENT_TYPE] => application/x-www-form-urlencoded [GATEWAY_INTERFACE] => CGI/1.1 [sCRIPT_URL] => /add_page.php [DOCUMENT_ROOT] => /home/users/web/b1384/moo.laissezfairelondonco/wolfcut [REMOTE_HOST] => host-78-151-213-160.as13285.net [uNIQUE_ID] => UOjAmwoBDKcAAG4JbDAAAAAh [sERVER_NAME] => wolfcut.co.uk [HTTP_REFERER] => http://wolfcut.co.uk/add_page.php [sERVER_ADMIN] => cgiadmin@yourhostingaccount.com [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_CONNECTION] => close [CONTENT_LENGTH] => 125 [sCRIPT_URI] => http://wolfcut.co.uk/add_page.php [sERVER_PORT] => 80 [HTTP_COOKIE] => TinyMCE_content_size=cw%3D571%26ch%3D121; PHPSESSID=3d30fa3c80ac91b2d2dd804bad7a3e91 [REMOTE_ADDR] => 78.151.213.160 [sERVER_PROTOCOL] => HTTP/1.0 [REQUEST_URI] => /add_page.php [HTTP_HOST] => wolfcut.co.uk [TZ] => EST5EDT ) [HTTP_ENV_VARS] => Array ( [PATH] => /usr/local/bin:/usr/bin:/bin [sCRIPT_NAME] => /add_page.php [REQUEST_METHOD] => POST [HTTP_ACCEPT] => text/html, application/xhtml+xml, */* [sCRIPT_FILENAME] => /home/users/web/b1384/moo.laissezfairelondonco/wolfcut/add_page.php [sERVER_SOFTWARE] => Apache/2 [REMOTE_PORT] => 40734 [HTTP_USER_AGENT] => Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) [HTTP_CACHE_CONTROL] => no-cache [HTTP_ACCEPT_LANGUAGE] => en-GB [CONTENT_TYPE] => application/x-www-form-urlencoded [GATEWAY_INTERFACE] => CGI/1.1 [sCRIPT_URL] => /add_page.php [DOCUMENT_ROOT] => /home/users/web/b1384/moo.laissezfairelondonco/wolfcut [REMOTE_HOST] => host-78-151-213-160.as13285.net [uNIQUE_ID] => UOjAmwoBDKcAAG4JbDAAAAAh [sERVER_NAME] => wolfcut.co.uk [HTTP_REFERER] => http://wolfcut.co.uk/add_page.php [sERVER_ADMIN] => cgiadmin@yourhostingaccount.com [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_CONNECTION] => close [CONTENT_LENGTH] => 125 [sCRIPT_URI] => http://wolfcut.co.uk/add_page.php [sERVER_PORT] => 80 [HTTP_COOKIE] => TinyMCE_content_size=cw%3D571%26ch%3D121; PHPSESSID=3d30fa3c80ac91b2d2dd804bad7a3e91 [REMOTE_ADDR] => 78.151.213.160 [sERVER_PROTOCOL] => HTTP/1.0 [REQUEST_URI] => /add_page.php [HTTP_HOST] => wolfcut.co.uk [TZ] => EST5EDT ) [PATH] => /usr/local/bin:/usr/bin:/bin [sCRIPT_NAME] => /add_page.php [REQUEST_METHOD] => POST [HTTP_ACCEPT] => text/html, application/xhtml+xml, */* [sCRIPT_FILENAME] => /home/users/web/b1384/moo.laissezfairelondonco/wolfcut/add_page.php [sERVER_SOFTWARE] => Apache/2 [REMOTE_PORT] => 40734 [HTTP_USER_AGENT] => Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) [HTTP_CACHE_CONTROL] => no-cache [HTTP_ACCEPT_LANGUAGE] => en-GB [CONTENT_TYPE] => application/x-www-form-urlencoded [GATEWAY_INTERFACE] => CGI/1.1 [sCRIPT_URL] => /add_page.php [DOCUMENT_ROOT] => /home/users/web/b1384/moo.laissezfairelondonco/wolfcut [REMOTE_HOST] => host-78-151-213-160.as13285.net [uNIQUE_ID] => UOjAmwoBDKcAAG4JbDAAAAAh [sERVER_NAME] => wolfcut.co.uk [HTTP_REFERER] => http://wolfcut.co.uk/add_page.php [sERVER_ADMIN] => cgiadmin@yourhostingaccount.com [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_CONNECTION] => close [CONTENT_LENGTH] => 125 [sCRIPT_URI] => http://wolfcut.co.uk/add_page.php [sERVER_PORT] => 80 [HTTP_COOKIE] => TinyMCE_content_size=cw%3D571%26ch%3D121; PHPSESSID=3d30fa3c80ac91b2d2dd804bad7a3e91 [REMOTE_ADDR] => 78.151.213.160 [sERVER_PROTOCOL] => HTTP/1.0 [REQUEST_URI] => /add_page.php [HTTP_HOST] => wolfcut.co.uk [TZ] => EST5EDT [title] => Films [category] => Select One [description] => Great Film [content] => Bourne Identity [submit_button] => Add This Page [TinyMCE_content_size] => cw=571&ch=121 [phpSESSID] => 3d30fa3c80ac91b2d2dd804bad7a3e91 [php_SELF] => /add_page.php [REQUEST_TIME] => 1357430939 [argv] => Array ( ) [argc] => 0 [_POST] => Array ( [title] => Films [category] => Select One [description] => Great Film [content] => Bourne Identity [submit_button] => Add This Page ) [HTTP_POST_VARS] => Array ( [title] => Films [category] => Select One [description] => Great Film [content] => Bourne Identity [submit_button] => Add This Page ) [_GET] => Array ( ) [HTTP_GET_VARS] => Array ( ) [_COOKIE] => Array ( [TinyMCE_content_size] => cw=571&ch=121 [phpSESSID] => 3d30fa3c80ac91b2d2dd804bad7a3e91 ) [HTTP_COOKIE_VARS] => Array ( [TinyMCE_content_size] => cw=571&ch=121 [phpSESSID] => 3d30fa3c80ac91b2d2dd804bad7a3e91 ) [_SERVER] => Array ( [PATH] => /usr/local/bin:/usr/bin:/bin [sCRIPT_NAME] => /add_page.php [REQUEST_METHOD] => POST [HTTP_ACCEPT] => text/html, application/xhtml+xml, */* [sCRIPT_FILENAME] => /home/users/web/b1384/moo.laissezfairelondonco/wolfcut/add_page.php [sERVER_SOFTWARE] => Apache/2 [REMOTE_PORT] => 40734 [HTTP_USER_AGENT] => Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) [HTTP_CACHE_CONTROL] => no-cache [HTTP_ACCEPT_LANGUAGE] => en-GB [CONTENT_TYPE] => application/x-www-form-urlencoded [GATEWAY_INTERFACE] => CGI/1.1 [sCRIPT_URL] => /add_page.php [DOCUMENT_ROOT] => /home/users/web/b1384/moo.laissezfairelondonco/wolfcut [REMOTE_HOST] => host-78-151-213-160.as13285.net [uNIQUE_ID] => UOjAmwoBDKcAAG4JbDAAAAAh [sERVER_NAME] => wolfcut.co.uk [HTTP_REFERER] => http://wolfcut.co.uk/add_page.php [sERVER_ADMIN] => cgiadmin@yourhostingaccount.com [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_CONNECTION] => close [CONTENT_LENGTH] => 125 [sCRIPT_URI] => http://wolfcut.co.uk/add_page.php [sERVER_PORT] => 80 [HTTP_COOKIE] => TinyMCE_content_size=cw%3D571%26ch%3D121; PHPSESSID=3d30fa3c80ac91b2d2dd804bad7a3e91 [REMOTE_ADDR] => 78.151.213.160 [sERVER_PROTOCOL] => HTTP/1.0 [REQUEST_URI] => /add_page.php [HTTP_HOST] => wolfcut.co.uk [TZ] => EST5EDT [php_SELF] => /add_page.php [REQUEST_TIME] => 1357430939 [argv] => Array ( ) [argc] => 0 ) [HTTP_SERVER_VARS] => Array ( [PATH] => /usr/local/bin:/usr/bin:/bin [sCRIPT_NAME] => /add_page.php [REQUEST_METHOD] => POST [HTTP_ACCEPT] => text/html, application/xhtml+xml, */* [sCRIPT_FILENAME] => /home/users/web/b1384/moo.laissezfairelondonco/wolfcut/add_page.php [sERVER_SOFTWARE] => Apache/2 [REMOTE_PORT] => 40734 [HTTP_USER_AGENT] => Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) [HTTP_CACHE_CONTROL] => no-cache [HTTP_ACCEPT_LANGUAGE] => en-GB [CONTENT_TYPE] => application/x-www-form-urlencoded [GATEWAY_INTERFACE] => CGI/1.1 [sCRIPT_URL] => /add_page.php [DOCUMENT_ROOT] => /home/users/web/b1384/moo.laissezfairelondonco/wolfcut [REMOTE_HOST] => host-78-151-213-160.as13285.net [uNIQUE_ID] => UOjAmwoBDKcAAG4JbDAAAAAh [sERVER_NAME] => wolfcut.co.uk [HTTP_REFERER] => http://wolfcut.co.uk/add_page.php [sERVER_ADMIN] => cgiadmin@yourhostingaccount.com [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_CONNECTION] => close [CONTENT_LENGTH] => 125 [sCRIPT_URI] => http://wolfcut.co.uk/add_page.php [sERVER_PORT] => 80 [HTTP_COOKIE] => TinyMCE_content_size=cw%3D571%26ch%3D121; PHPSESSID=3d30fa3c80ac91b2d2dd804bad7a3e91 [REMOTE_ADDR] => 78.151.213.160 [sERVER_PROTOCOL] => HTTP/1.0 [REQUEST_URI] => /add_page.php [HTTP_HOST] => wolfcut.co.uk [TZ] => EST5EDT [php_SELF] => /add_page.php [REQUEST_TIME] => 1357430939 [argv] => Array ( ) [argc] => 0 ) [_FILES] => Array ( ) [HTTP_POST_FILES] => Array ( ) [_REQUEST] => Array ( [title] => Films [category] => Select One [description] => Great Film [content] => Bourne Identity [submit_button] => Add This Page [TinyMCE_content_size] => cw=571&ch=121 [phpSESSID] => 3d30fa3c80ac91b2d2dd804bad7a3e91 ) [live] => [contact_email] => jizzwit@gmail.com [HTTP_SESSION_VARS] => Array ( [user_admin] => 1 [user_id] => 2 [username] => shimewaza [user_not_expired] => 1 ) [_SESSION] => Array ( [user_admin] => 1 [user_id] => 2 [username] => shimewaza [user_not_expired] => 1 ) [user_admin] => 1 [user_id] => 2 [username] => shimewaza [user_not_expired] => 1 [page_title] => Add a Site Content Page [pages] => Array ( [Home] => index.php [About] => about.php [Contact] => contact.php [Register] => register.php ) [this_page] => add_page.php [v] => register.php [k] => Register [dbc] => mysqli Object ( ) [add_page_errors] => Array ( ) [t] => Films ) ) ) ) ==================== END
  11. Hi Jon When I try the variation code, I get this: Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in /hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/add_page.php on line 33 I can't see where the syntax error is because I have copied the code thoroughly from the page 109. =============== When I try the orginal code, there is no error message. Only keeps asking me to "Please select a category!"
  12. Hello again. Problem: Every time I am logged in as administrator to add content, it doesn't allow me to submit the "Add This Page". Instead, it keeps asking me to "Please select a category!" - which I have. Current code I am using for 'validating category' (as on page 109) 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!'; } What I have tried I have tried the other variation of: if (isset($_POST['category'] && (int) $_POST['category'] >= 1)) { $cat = $_POST['category']; } else { // No category selected. $add_page_errors['category'] = 'Please select a category!'; } But this keeps on sending me the error on the line. What do you think I should do? Many thanks
  13. Thanks Larry! I mean it. Thank you for dedicating so much time on the forums for everyone, and the great books on the subject. It's going to help a lot of people get ahead and become self-sufficient. Best wishes to you and all the advisers on these forums - really, if anyone is listening, where else can complete strangers get help like this from other complete strangers in such a way.....
  14. on the brink of New Year with one last question before 2013.... Parse error: syntax error, unexpected T_STRING in /hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/includes/login.inc.php on line 27 This is really obvious (sytax error), not so, because I have been through each line over 10 times; compared it to the code in the Ecommerce book and copied / paste from the downloaded code. So I can't see where I have left out a bracket or a semi-colon. Here's the code for login.inc.php from example one: <?php $login_errors = array(); if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { $e = mysqli_real_escape_string ($dbc, $_POST['email']); } else { $login_errors['email'] = 'Please enter a valid email address!'; } // Validate the password: if (!empty($_POST['pass'])) { $p = mysqli_real_escape_string ($dbc, $_POST['pass']); } else { $login_errors['pass'] = 'Please enter your password!'; } if (empty($login_errors)) { // OK to proceed! // Query the database and is line 27 where syntax error is supposed to be $q = "SELECT id, username, type, IF(date_expires >= NOW(), true, false) FROM users WHERE (email='$e' AND pass='" SHA1($p) "')"; $r = mysqli_query ($dbc, $q); if (mysqli_num_rows($r) == 1) { // A match was made. // Get the data: $row = mysqli_fetch_array ($r, MYSQLI_NUM); // If the user is an administrator, create a new session ID to be safe: // This code is created at the end of Chapter 4: if ($row[2] == 'admin') { session_regenerate_id(true); $_SESSION['user_admin'] = true; } // Store the data in a session: $_SESSION['user_id'] = $row[0]; $_SESSION['username'] = $row[1]; // Only indicate if the user's account is not expired: if ($row[3] == 1) $_SESSION['user_not_expired'] = true; } else { // No match was made. $login_errors['login'] = 'The email address and password do not match those on file.'; } } // End of $login_errors IF. // Omit the closing PHP tag to avoid 'headers already sent' errors!
  15. Thanks Larry - interesting read. Something I will have to delve into after I complete both your examples in the Ecommerce book. In the meantime I've made good with SHA1 and amending the database to CHAR (40), as suggested on page 135 of the php and mysql book (4th edition) Speak soon, I'm working on the login.inc.php script and encountering errors there too. Hopefully I can make full use of your brilliant books.
  16. Hi Larry - I used varbinary because that was the example given in the Ecommerce book. Apparently hash_hmac doesn't work on my hosting server, so I made do with SHA1, what do you recommend I use instead? Best wishes for 2013
  17. I am also having this Fatal Error message in the login.inc.page: Call to undefined function_get_password_hash() I tried the above technique by changing it to SHA1 ($p), but it doesn't seem to work this time. Any suggestions? by the way.... Happy New Year!
  18. woooo - hoooo. Problem solved.... here's how: firstly: went into mysql.inc.php and changed the "mysql_real_escape_string" from hash hmac to simply SHA1 secondly: went into register.php and on "INSERT INTO..." line where you add user to database, I deleted the "create_password_hash" and replaced it with "SHA1" thirdly: upon registering a new user, I magically recieved an email confirmation without "Fatal Error" Thank you Jonathon for giving me the lead on this. I then found out the rest using a combination of PHP and MySQL (4th edition) by Larry to understand the all about passwords and SQL injections and applying it to the Ecommerce book. Question: According to the book, SHA1 is not that secure; and on my phpmyadmin on the password field I am using Varbinary(32), instead of CHAR(40), as recommended in Larrys PHP and MySQL book, which still works fine in registering a new user. (two questions here I know) - will this pose a problem later??? ================================== I am a newbie, so will be definitely asking a lot more questions. I am determined to complete both examples on the Ecommerce book ... so please bear with me advanced users
  19. PHP VERSION 5.3.13 PHPMYADMIN VERSION 5.0.91 Hello everyone. One simple question: if my hosting server doesn't support hash_hmac(), where do I insert this line of syntax in the 'registration.php' file as advised on page 79, chapter 4: return mysql_real_escape_string ($dbc, sha1 ($password, true)); Error message goes like this: Fatal error: Call to undefined function create_password_hash() in /hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/register.php on line 72 Line 72 of register.php goes like this: $q = "INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('$u', '$e', '" . create_password_hash($p) . "', '$fn', '$ln', ADDDATE(NOW(), INTERVAL 1 MONTH) )"; Any advice much appreciated
  20. Thank you everyone! I am learning a lot already. It wont be the last question I post on this forum though.
  21. OMG ==== you are an absolute genius Totally worked: Before I had this in the index.php: require ('MYSQL'); And upon your advice, it is now this: require ('./includes/mysql.inc.php'); I'm not sure if you have the Larry's book, but I must have mis-understood what he meant on page 70 ".....The database connection script can be included by referring to the MYSQL constant, defined in the configuration file. This means that even if you change the name or location of mysql.inc.php, you have to change only one line in the configuration file and all your pages will still include that script properly." ---- I thought this meant require ('MYSQL'); can locate the mysql.inc.php anywhere (silly me) It's so difficult to learn this solely from book - so really glad you fixed this for me so quick!
  22. Hiya - I'm having difficulty connecting to the database with the mysql.inc.php. Here's the error message: <-- error message ========== An error occurred in script '/hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/index.php' on line 9: require(/home/users/web/b1384/moo.laissezfairelondonco/wolfcut/wolfcut/includes/mysql.inc.php) [function.require]: failed to open stream: No such file or directory ========= --> Really basic, I know, but I'm trying to follow an examples between pages 49-71 in the ecommerce book and the above error keep happening. As far as I can gather, the 'user, password, host, db name' are all correct. I am directly uploading files to server and full error code can be seen at: http://www.wolfcut.co.uk/ Assistance much appreciated
  23. Hiya - I'm having difficulty connecting to the database with the mysql.inc.php. Here's the error message: <-- error message ========== An error occurred in script '/hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut/index.php' on line 9: require(/home/users/web/b1384/moo.laissezfairelondonco/wolfcut/wolfcut/includes/mysql.inc.php) [function.require]: failed to open stream: No such file or directory ========= --> Really basic, I know, but I'm trying to follow an example in another book and the above error keep happening. As far as I can gather, the 'user, password, host, db name' are all correct. Assistance much appreciated
  24. ..... begining of code goes like this: <?php require ('./includes/config.inc.php'); require (MYSQL); if ($_SERVER['REQUEST_METHOD'] == 'POST') { include ('./includes/login.inc.php'); } include ('./includes/header.html'); ?> <h3>Welcome</h3> <p>Welcome to Knowledge is Power, a site dedicated to keeping you up to date on the Web security and programming information you need to know. Blah, blah, blah. Yadda, yadda, yadda.</p> ========================== I've paid up for a hosting company 'Fatcow', so do I still need that open? I'm now going to double check the config.php script and see what I can find.... Thank you Antonio / Bill131
×
×
  • Create New...