Jump to content
Larry Ullman's Book Forums

Paul_Blackpool

Members
  • Posts

    68
  • Joined

  • Last visited

Everything posted by Paul_Blackpool

  1. Thanks Larry I've managed to fix it. For ref if anyone else is having the same problem: This bit // URL is http:// plus the host name plus the current directory $url = 'http://localhost/tuition'; Should be: // URL is http:// plus the host name plus the current directory: $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); It all works fine now. I couldn't see the wood for the trees as we say in the UK
  2. Sorry to be a pain Larry I've followed all the instruction to the letter and the error I am getting now is Warning: require_once(includes/login_functions.inc.php): failed to open stream: No such file or directory in D:\xampp\htdocs\tuition\loggedin.php on line 9 Fatal error: require_once(): Failed opening required 'includes/login_functions.inc.php' (include_path='.;D:\xampp\php\PEAR') in D:\xampp\htdocs\tuition\loggedin.php on line 9 The login pages are <?php # Script 11.1 - login_page_inc.php // This page prints any errors associated with logging in. // and it creates the entire login page including the form. // Include the header: $page_title = 'Login'; include ('header.html'); // Print any error messages, if they excist: if (!empty($_errors)) { echo '<h1>Error!</h1> <p class="error">The following error(s) occured:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p>'; } // Display the form ?> <h1>Login</h1> <form action="loggedin.php" method="post"> <p>Email Address: <input type="text" name="email" size="20" maxlengh="80" /> <p>Password: <input type="password" name="pass"size="20" maxlengh="20" /></p> <p><input type="submit" name="submit" value="Login" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php // Include the footer include ('footer.html'); ?> <?php # Script 11.2 - login_functions_inc.php // This page defines 2 functions used by the login/logout process /* This function determins and returns an absoloute URL * It takes one argument: the page that includes the URL. * the argument defaults to index.php */ function absoluite_url ($page = 'index.php') { // Start defining the URL // URL is http:// plus the host name plus the current directory $url = 'http://localhost/tuition'; // Remove any trailing slashes: $url = rtrim($url, '/\\'); // Add the page $url .= '/' . $page; // Return the URL: return $url; } // End of absoluite_url() function /* This function validates the form data (the email address and password) * If both are present the database is queried * The function requires a database connection * The function returns an array of information, including: * -a TRUE/FALSE variable indicating success. 9 An array of eithers errors or the database result. */ function check_login($dbc, $email = '', $pass = '') { $errors = array(); // Initiolise the error array. // validate the email address: if (empty($email)) { $errors[] = 'You forgot to enter your email address.'; } else { $e = mysqli_real_escape_string($dbc, trim($email)); } // validate the password: if (empty($pass)) { $errors[] = 'You forgot to enter your password.'; } else { $p = mysqli_real_escape_string($dbc, trim($pass)); } if (empty($errors)) { // If everythings OK. // Retreive the user_id and first_name for that email/password combination. $q = "SELECT user_id, first_name FROM users WHERE email='$e' AND pass=SHA1('$p')"; $r = @mysqli_query ($dbc, $q); // run the query. // Check the result if (mysqli_num_rows($r) == 1) { // Fetch the record $row = mysqli_fetch_array ($r, MYSQLI_ASSOC); // Return true and the record. return array(true, $row); } else { // Not a match. $errors[] = 'The email address and password entered do not match those on file'; } } // end of empty(errors0 IF // Return faulse and errors: return array(false, $errors); } // End of check_login() function ?> <?php // Script 11.3 - login.php // This page processes the login form submission. // Upon successfull login the user is re-directed. // Two include files are required // Send NOTHING to the web browser prior to the setcookie() lines! // Check if the form has been submitted if(isset($_POST['submitted'])) { // For processing the login require_once ('includes/login_functions_inc.php'); // Connect to the database require_once ('conn.php'); // check the login: list ($check, $data) = check_login($dbc, $_POST['email'], $_POST['pass']); if ($check) { // OK! // Set the cookies: setcookie ('user_id', $data['user_id']); setcookie ('first_name', $data['first_name']); // Redirect $url = absolute_url ('loggedin.php'); header("Location: $url"); exit(); // quite the script. } else { // If unsuccessfull // Assign $ data to $ errors for error reporting. // in the login_page.inc.php file $errors = $data; } mysqli_close($dbc); // Close the database connection } // End of main submit conditional // Create the page include ('includes/login_page_inc.php'); ?> <?php # Script 11.4 - loggedin.php // the user is re-directed here from login.php // If no cookie is present if (!isset($_COOKIE['user_id'])) { // need the functions to create an absoloute URL: require_once ('includes/login_functions.inc.php'); $url = absolute_url(); header("Location: $url"); exit(); // Quit the script. } // Set the page title and include the HTML Header. $page_title = 'Logged In!'; include ('includes/header.html'); // Print the customised message: echo "<h1>Logged In!</h1> <p>You are now logged in, {$_COOKIE['first_name']}!</p> <p><a href=\"logout.php\">Logout</a></p>"; include ('includes/footer.html'); ?>
  3. Thanks for the reply Larry. The URL is: http://localhost/login.php Hope this helps Also The login.php page is located at C:/xampp/htdocs/tuition The login_page_inc.php and login_functions_inc.php are located at C:/xampp/htdocs/tuition/includes - in the same includes directory as the header and footer. Thanks
  4. Sorry Larry i forgot to include the login.php. <?php // Script 11.3 - login.php // This page processes the login form submission. // Upon successfull login the user is re-directed. // Two include files are required // Send NOTHING to the web browser prior to the setcookie() lines! // Check if the form has been submitted if(isset($_POST['submitted'])) { // For processing the login require_once ('includes/login_functions_inc.php'); // Connect to the database require_once ('conn.php'); // check the login: list ($check, $data) = check_login($dbc, $_POST['email'], $_POST['pass']); if ($check) { // OK! // Set the cookies: setcookie ('user_id', $data['user_id']); setcookie ('first_name', $data['first_name']); // Redirect $url = absolute_url ('loggedin.php'); header("Location: $url"); exit(); // quite the script. } else { // If unsuccessfull // Assign $ data to $ errors for error reporting. // in the login_page.inc.php file $errors = $data; } mysqli_close($dbc); // Close the database connection } // End of main submit conditional // Create the page include ('includes/login_page_inc.php'); ?> If I try and login i now get the error Object not found!The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. Error 404 localhost Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.9
  5. Thanks Larry. I must be doing something wrong here. I have posted the login page and the login script. If i try and login using incorrect credentials i don't get any error messages and if i enter the correct credentials i get no indication i am logged in. Both the login_page.inc.php and the login_functions.inc.php are both in the includes folder as the book tells me to. <?php # Script 11.1 - login_page_inc.php // This page prints any errors associated with logging in. // and it creates the entire login page including the form. // Include the header: $page_title = 'Login'; include ('header.html'); // Print any error messages, if they exist: if (!empty($_errors)) { echo '<h1>Error!</h1> <p class="error">The following error(s) occured:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p>'; } // Display the form ?> <h1>Login</h1> <form action="../login.php" method="post"> <p>Email Address: <input type="text" name="email" size="20" maxlengh="80" /> <p>Password: <input type="password" name="pass"size="20" maxlengh="20" /></p> <p><input type="submit" name="submit" value="Login" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php // Include the footer include ('footer.html'); ?> <?php # Script 11.2 - login_functions_inc.php // This page defines 2 functions used by the login/logout process /* This function determins and returns an absoloute URL * It takes one argument: the page that includes the URL. * the argument defaults to index.php */ function absoluite_url ($page = 'index.php') { // Start defining the URL // URL is http:// plus the host name plus the current directory $url = 'http//localhost/tuition'; // Remove any trailing slashes: $url = rtrim($url, '/\\'); // Add the page $url .= '/' . $page; // Return the URL: return $url; } // End of absoluite_url() function /* This function validates the form data (the email address and password) * If both are present the database is queried * The function requires a database connection * The function returns an array of information, including: * -a TRUE/FALS variable indicating success. 9 An array of eithers errors or the database result. */ function check_login($dbc, $email = '', $pass = '') { $errors = array(); // Initiolise the error array. // validate the email address: if (empty($email)) { $errors[] = 'You forgot to enter your email address.'; } else { $e = mysqli_real_escape_string($dbc, trim($email)); } // validate the password: if (empty($pass)) { $errors[] = 'You forgot to enter yourpassword.'; } else { $p = mysqli_real_escape_string($dbc, trim($pass)); } if (empty($errors)) { // If everythings OK. // Retreive the user_id and first_name for that email/password combination. $q = "SELECT user_id, first_name FROM users WHERE email='$e' AND pass=SHA1('$p')"; $r = @mysqli_query ($dbc, $q); // run the query. // Check the result if (mysqli_num_rows($r) == 1) { // Fetch the record $row = mysqli_fetch_array ($r, MYSQLI_ASSOC); // Return true and the record. return array(true, $row); }else { // Not a match. $errors[] = ' The email address and password entered do not match those on file'; } } // end of empty(errors) IF // Return faulse and errors: return array(false, $errors); } // End of check_login() function ?>
  6. Sorry to be a pain but I'm a little confused where to enter the server and directory name, also if they should be in upper or lower case. I'm using xampp on localhost and the directory path is D://xampp/htdocs/tuition. If someone could point me in the right direction. I've already tried a number of computations but I must be doing something wrong, i cant seem to get it to work. // Start defining the URL // URL is http:// plus the host name plus the current directory $url = 'http//' . $_localhost['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Remove any trailing slashes: $url = rtrim($url, '/\\');
  7. I am having a problem when I click on the link that this script creates. My structure is D://xampp/uploads (This is where the images have been uploaded to) My main files are in D://xampp/htdocs/tuition. When I publish the script in the browser it sees the images in the table I.E.: Image Name - Image Size basketball.jpg 154kb penguins.jpg 89kb I have checked and double checked the code. I have also tried replacing line 46 from $dir = '../../uploads'; // Define the directory to view. to $dir = 'D://xampp/uploads'; // Define the directory to view. But i still get the same error: The page code 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=iso-8859-1" /> <title>Images</title> <script language="JavaScript"> <!-- // Hide from old browsers. // Make a pop-up window function: function create_window (image, width, height) { // Add some pixels to the width and height: width = width + 10; height = height + 10; // If the window is already open, // resize it to the new dimensions: if (window.popup && !window.popup.closed) { window.popup.resizeTo(width, height); } // Set the window properties: var specs = "location=no, scrollbars=no, menubars=no, toolbars=no, resizable=yes, left=0, top=0, width=" + width + ", height=" + height; // Set the URL: var url = "show_image.php?image=" + image; // Create the pop-up window: popup = window.open(url, "ImageWindow", specs); popup.focus(); } // End of function. //--></script> </head> <body> <p>Click on an image to view it in a separate window.</p> <table align="center" cellspacing="5" cellpadding="5" border="1"> <tr> <td align="center"><b>Image Name</b></td> <td align="center"><b>Image Size</b></td> </tr> <?php # Script 10.4 - images.php // This script lists the images in the uploads directory. $dir = '../../uploads'; // Define the directory to view. $files = scandir($dir); // Read all the images into an array. // Display each image caption as a link to the JavaScript function: foreach ($files as $image) { if (substr($image, 0, 1) != '.') { // Ignore anything starting with a period. // Get the image's size in pixels: $image_size = getimagesize ("$dir/$image"); // Calculate the image's size in kilobytes: $file_size = round ( (filesize ("$dir/$image")) / 1024) . "kb"; // Make the image's name URL-safe: $image = urlencode($image); // Print the information: echo "\t<tr> \t\t<td><a href=\"javascript:create_window('$image',$image_size[0],$image_size[1])\">$image</a></td> \t\t<td>$file_size</td> \t</tr>\n"; } // End of the IF. } // End of the foreach loop. ?> </table> </body> </html> However when I click in the link to show the image in a popup window I get the error: Object not found!The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. Error 404 localhost Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.9
  8. Just got a little stuck. Iv'e created a form but I cant get the items from my multi select items list into the database. Everything else works fine could just do with a little help. PHP <?php # script 8.5 - register.php # 2 $page_title = 'Register'; include ('../Includes/header.html'); // Check if the form has been submitted: if (isset($_POST['submitted'])) { require_once ('../conn/mysqli_connect.php'); // connect to the database. $errors = array(); // Initialise error array // Check for a first name: if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = mysqli_real_escape_string($dbc,trim($_POST['first_name'])); } // Check for last name: if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = mysqli_real_escape_string($dbc,trim($_POST['last_name'])); } // Check for an email address: if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = mysqli_real_escape_string($dbc,trim($_POST['email'])); } // Check for a password and match against the confirmed password: if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'Your password did not match your confirm password.'; } else { $p = mysqli_real_escape_string($dbc,trim($_POST['pass1'])); } } else { $errors[] = 'You forgot to enter your password.'; } if (empty($errors)) { // If everythings OK: // Register the user into the database. // Make the query: $q = "INSERT INTO users (first_name, last_name, email, pass, items_list, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )"; $r = mysqli_query ($dbc, $q); // Run the query: if ($r) { // if it ran OK. // Print the message echo '<h1>Thank You</h1> <p>You are now registered. In chapter 11 you will actually be able to login!</p><p><br /></p>'; } else { // If it did not run OK // message echo '<h1>System Error</h1> <p class ="error">You could not be registered due to a system error. Please try in a little while. We appologise for any inconvenience,</p>'; // Debug message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // end of the if ($r) IF mysqli_close($dbc); // Close the database connection. // include the footer and quit the script. include ('../Includes/3.4_3.4_footer.html'); exit(); } else { // Report the errors. echo '<h1>Error!</h1> <p class="error">The following error(s) occured:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // End of if (empty($errors)) IF myli_close($dbc); // Close the database. } // End of mail submitt. ?> HTML Form <style type="text/css"> #apDiv1 { position:absolute; width:200px; height:115px; z-index:1; left: 107px; top: 229px; } </style> <h1>Register</h1> <form action="register_2.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlengh="20" value="<?php if(isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p>Last name: <input type="text" name="last_name" size="15" maxlengh="24" value="<?php if(isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="20" maxlengh="80" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Password: <input type="password" name="pass1" size="10" maxlengh="20" /></p> <div id="apDiv1"></div> <p>Confirm Password: <input type="password" name="pass2" size="10" maxlengh="20" /></p> <P> List: <select name="items_list[]" multiple size="1" > <option>Item 1</option> <option>Item 2</option> <option>Item 3</option> </select> <p><input type="submit" name="submit" value="register" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('../Includes/3.4_3.4_footer.html'); ?>
  9. I have a multi select combo box on my site. If the user fills in the form wrong the site retains all the information already entered, however the multi select combo box comes back with the selections de-selected. How can I get the combo box to retain the values entered when the user happens to fill something wrong elsewhere on the form? <select name="Skills[]" multiple size="1" id="Combobox1"> <option value="LGV Class 1">LGV Class 1</option> <option value="LGV Class 2">LGV Class 2</option> <option value="7.5 Ton Drivers">7.5 Ton Drivers</option> <option value="Non LGV Driver">Non LGV Driver</option> <option value="Fork Lift Driver">Fork Lift Driver</option> <option value="Garage Staff">Garage Staff</option> <option value="Transport Manager">Transport Manager</option> <option value="Traffic Planner">Traffic Planner</option> </select>
  10. I am getting to the end of Edition 3 and thinking about Edition 4. What’s the deference or whats new in Edition 4?
  11. Whe I try to upload a file (Chapter 10 file_upload.php) I get the following errors Warning: move_uploaded_file(../tmp/agriculture.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\trsb\upload_image.php on line 28 Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\phpA805.tmp' to '../tmp/agriculture.jpg' in C:\xampp\htdocs\trsb\upload_image.php on line 28 The folder I have created is called "tmp" and I followed the instructions for the local server. here is the line the error is referring to: // Move the file over if(move_uploaded_file($_FILES['upload']['tmp_name'],"../tmp/{$_FILES['upload']['name']}")) { echo '<p><em>The file has been uploaded</em></p>'; } // End of move . IF.
  12. Thanks Larry I started Mercury in the xammp control panel and it worked fine
  13. Thanks Larry and Jonathon. I followed the link and also looked at other sites for a soloution and they all tell me to do the same thing but it's still not working. I have posted the relavent bit of the php.ini and also the page code. Don't think the code is wrong as the form all works correctly. [mail function] XAMPP: Comment out this if you want to work with an SMTP Server like Mercury SMTP = mail.me.co.uk sendmail_from = paul@me.co.uk <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Contact Me</title> </head> <body> <h1>Contact Us</h1> <?php # Script 10.1 = email.php include ('includes/header.html'); // Check for the form submission if (isset($_POST['submitted'])) { // Minimal form validation if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['comments']) ) { // Create the body $body = "Name: {$_POST['name']}\n\nComments: {$_POST['comments']}"; // make it longer than 70 caracters long: $body = wordwrap($body, 70); // Send the email mail('paul@me.co.uk', 'Contact Form Submission', $body, "Form: {$_POST['email']}"); //Print the message: echo '<p style="font-weight: bold; color: red">Thank you for contacting us. We will reply some day,</em></p>'; // Clear $_POST (So that the form's not sticky): $_POST = array(); } else { echo '<p style="font-weight: bold; Color: #C00">Please go back and fill out the form correctly.</p>'; } } // End of mail isset() IF. // Now create the HTML form ?> <p>Please use this form to contact us.</p> <form action="email.php" method="post"> <p>Name: <input type="text" name="name" size="30" maxlengh="60" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="30" maxlengh="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Comments: <textarea name="comments" rows="5" cols="30"><?php if (isset($_POST['comments'])) echo $_POST['comments']; ?></textarea></p> <p><input type="submit" name="submit" value="send!" /></p> <input type="hidden" name="submitted" value="true" /> </form> <?php include ('includes/footer.html'); ?> </body> </html> ; smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from sendmail_from = paul@wcrltd.co.uk
  14. Not sure if this is the right place to ask this question so appologies in advance if I'm off track here. I am using a local server XAMMP to work my way through Larry's book. I have reached "Script 10.1" Sending emails, however the email doesn't go anywhere. Is there some setting in XAMMP to make the email function work. My emails are nothing strange its just "paul@me.com" what I'm saying its not one of those accounts that some local and indeed remote servers do not like. As a side bar I have the correct script as I posted the page to a remote server and it worked fine, so I know it's not the script. I just thought it would be nice to have all the pages working together on the local server.
  15. Thanks it's now fixed. Edward you were right POST_ was missing. Benjamin yes the $'in' was wrong it should be '$in' Margaux the problem was indeed this line. if (!empty($_POST['pass1'])) { As soon as I corrected those it all worked fine. I do think that if you do get a problem with the code you either spot it straight away or you spend that much time looking at it you completely look straight through the error. When you get to the stage where you can’t see what’s wrong I think it’s best another pair of eyes look through it. Sorry for the confusion with the original post it was the "Password" that threw up the error not the "email" as I said at first. Thanks again Paul
  16. Thanks Edward. You know I looked at this code about 20 times and never noticed. Just need to sort the error out now.
  17. Could anyone help. I keep getting the message "You forgot to enter your email address" when I have. Also the forms not sticky. <?php # script 8.3 = register.php $page_title = 'Register'; include ('includes/header.html'); // check if the form has been submitted: if (isset($_POST['submitted'])) { $errors = array(); // initianalise an error array: // Check for first name: if (empty($_POST['first_name'])) { $errors[] = 'You forgot to enter your First Name.'; } else { $fn = trim($_POST['first_name']); } // Check for last name: if (empty($_POST['last_name'])) { $errors[] = 'You forgot to enter your Last Name.'; } else { $ln = trim($_POST['last_name']); } // Check for an email address: if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your Email Address.'; } else { $e = trim($_POST['email']); } // Check for password and match against the confirmed password: if (empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'Your password did not match your confirmed password.'; } else { $p = trim($_POST['pass1']); } } else { $errors[] = 'You forgot to enter your password.'; } if (empty($errors)) { // if everythings OK // Register the user in the database require_once ('mysqli_connect.php'); // Connect to the database. // make the query: $q = "INSERT INTO l30trsb_jobsite (first_name, last_name, email, pass, registration_date) VALUES ('$fn', $'ln', '$e', SHA1('$p'), NOW() )"; $r = @mysqli_query ($dbc, $q); // Run the query: if ($r) { // If it ran OK. // Print the message: echo '<h1>Thank you for registering!</h1> <p>You are now registered. In chapter 11 you will actually be able to login!</p><p><br /></p>'; } else { // If it did not run OK: // Public message: echo '<h1>System Error</h1> <p class="error">You could not be registered. Please try again in a short while.</p>'; // Debugging message: echo '<p>' .mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; }// End of if ($r) IF. mysqli_close($dbc); // Close the database connection. // Include the footer and quit the script: include ('includes/footer.html'); exit(); } else { // Report the errors: echo '<h1>Error!</h1> <p class="error">The following error(s) occured:<br />'; foreach ($errors as $msg) { // Print each error. echo " . $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } // End of if (empty($errors)) IF. } // End of main submit conditional ?> <h1>Register</h1> <form action="register.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlengh="20" value="<?php if (isset($POST['first_name'])) echo $_POST['first_name']; ?>" /> </p> <p>Last Name: <input type="text" name="last_name" size="15" maxlengh="40" value="<?php if (isset($POST['last_name'])) echo $_POST['last_name']; ?>" /> </p> <p>Email Address: <input type="text" name="email" size="20" maxlengh="80" value="<?php if (isset($POST['email'])) echo $_POST['email']; ?>" /> </p> <p>Password: <input type="password" name="pass1" size="10" maxlengh="20" /></p> <p>Confirm Password: <input type="password" name="pass2" size="10" maxlengh="20" /></p> <p><input type="submit" name="submit" value="Register" /><p/> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('includes/footer.html'); ?>
  18. Larry's book contained a link to www.edg3.co.uk. This link contained a template as the base for the header lesson. The link is not working and re-directs you to Larry's home page. I can't find this template on Larry's site. Could anyone post a link to the template please? Thanks Paul
  19. Rob been reading larry's book and by sanitised I take it you mean add this to the success page or do I add it to the form page? Thanks for the help <?php $first_name = strip_tags($_POST["first_name"]); ?>
  20. Sorry Rob This is the PHP thats on the page. I thought it was just something to do with sending the email: <?php function ValidateEmail($email) { $pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i'; return preg_match($pattern, $email); } if($_SERVER['REQUEST_METHOD'] == 'POST') { $mailto = 'paul@wcrltd.co.uk'; $mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto; $subject = 'Contact Form'; $message = 'Values submitted from Contact Form'; $success_url = './../mail_folder/success.php'; $error_url = './../mail_folder/fail.php'; $error = ''; $eol = "\n"; $max_filesize = isset($_POST['filesize']) ? $_POST['filesize'] * 1024 : 1024000; $boundary = md5(uniqid(time())); $header = 'From: '.$mailfrom.$eol; $header .= 'Reply-To: '.$mailfrom.$eol; $header .= 'MIME-Version: 1.0'.$eol; $header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol; $header .= 'X-Mailer: PHP v'.phpversion().$eol; if (!ValidateEmail($mailfrom)) { $error .= "The specified email address is invalid!\n<br>"; } if (!empty($error)) { $errorcode = file_get_contents($error_url); $replace = "##error##"; $errorcode = str_replace($replace, $error, $errorcode); echo $errorcode; exit; } $internalfields = array ("submit", "reset", "send", "captcha_code"); $message .= $eol; $message .= "IP Address : "; $message .= $_SERVER['REMOTE_ADDR']; $message .= $eol; foreach ($_POST as $key => $value) { if (!in_array(strtolower($key), $internalfields)) { if (!is_array($value)) { $message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol; } else { $message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol; } } } $body = 'This is a multi-part message in MIME format.'.$eol.$eol; $body .= '--'.$boundary.$eol; $body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol; $body .= 'Content-Transfer-Encoding: 8bit'.$eol; $body .= $eol.stripslashes($message).$eol; if (!empty($_FILES)) { foreach ($_FILES as $key => $value) { if ($_FILES[$key]['error'] == 0 && $_FILES[$key]['size'] <= $max_filesize) { $body .= '--'.$boundary.$eol; $body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol; $body .= 'Content-Transfer-Encoding: base64'.$eol; $body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol; $body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol; } } } $body .= '--'.$boundary.'--'.$eol; mail($mailto, $subject, $body, $header); header('Location: '.$success_url); exit; } ?>
  21. This is what's on the form page <script type="text/javascript" src="./jquery-1.7.2.min.js"></script> <script type="text/javascript"> <!-- function Validategeneral_contact_form(theForm) { var regexp; if (theForm.Editbox1.value == "") { alert("You Forgot To Enter Your First Name!"); theForm.Editbox1.focus(); return false; } //--> </script> <form name="general_contact_form" method="post" action="<?success.php; ?>" enctype="multipart/form-data" id="Form1" onsubmit="return Validategeneral_contact_form(this)"> <select name="title" size="1" id="Combobox1 title="Title:"> <option selected>Please Select</option> <option value="Mr.">Mr.</option> <option value="Mrs.">Mrs.</option> <option value="Miss.">Miss.</option> </select> <input type="text" id="Editbox1" name="first_name" value="" title="First Name:" placeholder="First Name:"> body> </html> and this is whats on the success page <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>You have successfully sent mail to TRSB and Tower Employment Services</title> <meta name="keywords" content="recruitment ageny, recruitment agencies in lancashire, recruitment agencies,recruitment agency, jobs in preston, jobs in blackpool, hgv / lgv driving jobs, waste and recycling jobs, commercial recruitment, commercial employment agencies in blackpool, nationwide recruitment, jobs, carears, student jobs, part time jobs, full time jobs, employment in lancashire, Jobs in lancashire, tower employment services, stubbs management services, west coast recruitment, chef jobs."> <meta name="author" content="Paul Stubbs 12/09/2012"> <meta name="generator" content="Tower Employment Services - http://www.trsb.co.uk"> </head> <body> <strong>Your email was successfully sent</strong> Your email was sent to us. You should expect to hear from us within<strong><em> two business days </body> </html>
  22. Rob You were right when the user fills in the form and presses submit it then re-directs them to a success page telling the user that the message has been sent. Would it help if I add the link so you can see the source code: http://www.trsb.co.uk/contact_folder/contact.php Do you think it would it be better to remove the javascript validation and replace it in php? It's just that the program I am using does all the validation by just ticking a few boxes.
×
×
  • Create New...