Jump to content
Larry Ullman's Book Forums

Paul_Blackpool

Members
  • Posts

    68
  • Joined

  • Last visited

Everything posted by Paul_Blackpool

  1. Sorted out the mail v email.php and now I get a different error as below Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\scripts\email.php on line 25 Copied in the php.ini mail function and also the sendmail.ini. [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = mail.crltd.co.uk ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from sendmail_from = paul@crltd.co.uk ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path ;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(), even in safe mode. ;mail.force_extra_parameters = ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename mail.add_x_header = Off ; Log all mail() calls including the full path of the script, line #, to address and headers ;mail.log = "C:\xampp\php\logs\php_mail.log" ; http://php.net/sql.safe-mode sql.safe_mode = Off sendmail.ini ; if your smtp server requires authentication, modify the following two lines ;auth_username=paul@crltd.co.uk ;auth_password=password ; if your smtp server uses pop3 before smtp authentication, modify the ; following three lines ;pop3_server=mail.crltd.co.uk ;pop3_username=paul@crltd.co.uk ;pop3_password=password ; to force the sender to always be the following email address, uncomment and ; populate with a valid email address. this will only affect the "MAIL FROM" ; command, it won't modify the "From: " header of the message content ;force_sender=me@localhost ; sendmail will use your hostname and your default_domain in the ehlo/helo ; smtp greeting. you can manually set the ehlo/helo name if required ;hostname=localhost
  2. I am at the email stage of the book, however I have come across a problem. Below id the error message I am getting. I am using xampp on a local server. 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. I also attach the page code below. Any help would be apreciated. <!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 Me</h1> <?php # Script 10.1 - email.php // Check 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 no longer than 70 caracters long: $body = wordwrap($body, 70); // Send the mail: mail('paul@me.co.uk', 'Contact form submission', $body, "From {$_POST['email']}"); // Print a message: echo '<p><em>Thank you for contacting me. I will reply some day.</em></p>'; // Clear $_POST (So that the forms not sticky): $_POST = array(); } else { echo '<p style="font-weight: bold; Color: #c00">Please fill out the form completley.</p>'; } } // End of main isset() IF. // Create the HTML form ?> <p>Please fill out this form to contact me.</p> <form action="mail.php" method="post"> <p>Name: <input type="text" name="name" size="30" maxlengh="60" value="<?php if (isset($_POST['name'])) echo $_post['email']; ?>" /></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> </body> </html>
  3. Thanks Larry. Never even thought to look although I think I will check all the spelling. That was one of the things wrong with my laptop I was typing and some of the letters were missing. PC World said the keyboard was faulty and replaced it with a new one.
  4. Sorry its taken a while to get back. My computer broke and had to go in for repair. I have taken all the @ s out and I now get the error: Fatal error: Call to undefined function msqli_connect() in C:\xampp\mysqli_connect.php on line 14 I am told this is something to do with xampp itself and I have to change a file? Have you come accross this before? Thanks in anticipation Paul
  5. Sorry to be a nusance, done that and I still get a blank page after I fill out the form. Enclosed a copy of mysqli_connect page of that helps. <?php # Script 8.2 - mysqli_connect.php // This file contains the database access information. // This file also establishes a connection to mysql // and selects the database // Set the database access information as Constants: DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', '*********'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', '************'); // Make the connection $dbc = @msqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); ?>
  6. Now I feel an idiot. Seen it </php # Script 8.2 - mysqli_connect.php <?php #
  7. I am having a problem with the register.php page. When I fill out the form I am getting errors. When I created the mysqli_connect page it returned a blank page when I tested it. I think thats what it should do. I have the form in c://xampp and I am assuming that's where it should be. I'm sailing through the php sections but getting stuck on the db sections. The errors are: System Error You could not be registered due to a system error. We appologise for any inconveniance. Notice: Undefined variable: dbc in C:\xampp\htdocs\scripts\register.php on line 65 Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\scripts\register.php on line 65 Query: INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('Peter', 'Stubbs', 'peter@test.com', SHA1('grund1gps'), NOW()) Notice: Undefined variable: dbc in C:\xampp\htdocs\scripts\register.php on line 69 Warning: mysqli_close() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\scripts\register.php on line 69 The register_php script is: <?php # Script 8.3 - register.php $page_title = 'register.php'; include ('includes/header.html'); // Check if the form has been submitted: if (isset($_POST['submitted'])) { $errors = array(); // Initialise 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 a password and match against confirmed password: if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'Your password did not match the 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 ('C://xampp/mysqli_connect.php'); // Connect to the db. // Make the query: $q = "INSERT INTO users (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 run OK. // Print the message: echo '<h1>Thank you!</h1> <p>You are now registered. In chapter 11 you will actually be able to log in!</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 due to a system error. We appologise for any inconveniance.</p>'; // Debug message: echo '<p>' .mysqli_error($dbc) .'<br /><br />Query: ' .$q . '</p>'; } // End of IF. mysqli_close($dbc); // Close the database. // 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 b/>\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } //End of if (empty($errors)) IF. } // End of mail 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'); ?> and the mysqli_connect script is </php # Script 8.2 - mysqli_connect.php // This file contains the database access information. // This file also establishes a connection to mysql // and selects the database // Set the database access information as Constants: DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'grund1g'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'mydatabase'); // Make the connection $dbc = @msqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to mysql: ' . mysqli_connect_error() );if ($dbc) { echo 'Connected'; } else { echo 'Not connected';} ?> Any help would be apreciated
  8. Thanks for that. I have changed the code and the error messages have now gone, however when I click register on the form I just get a blank page and when I checked the database the info had not been put into it.
  9. Hope you fixed it. I had the same problem and I was told to set up my server details and take out some ; in sendmail file. Cant remember where though.
  10. Thought I would be back but just not this soon. I am getting the following errror message: Notice: Undefined variable: ln in C:\xampp\htdocs\scripts\register.php on line 50 Notice: Undefined variable: e in C:\xampp\htdocs\scripts\register.php on line 50 All the rest of the form works fine giving all the correct error messages when I brake the form on purpose but I keep getting these two lines of errors when I try and submit the completed form. Could anyone help please I have includer the page code below. <?php # Script 8.3 - register.php $page_title = 'register.php'; include ('includes/header.html'); // Check if the form has been submitted: if (isset($_POST['submitted'])) { $errors = array(); // Initialise 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 { $fn = trim($_POST['last_name']); } // Check for an email address: if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $fn = trim($_POST['email']); } // Check for a password and match against confirmed password: if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'Your password did not match the 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 ('C://xampp/mysqli_connect.php'); // Connect to the db. // Make the query: $q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW())"; $r = @msqli_query ($dbc, $q); // Run the query if ($r) { // If it run OK. // Print the message: echo '<h1>Thank you!</h1> <p>You are now registered. In chapter 11 you will actually be able to log in!</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 due to a system error. We appologise for any inconveniance.</p>'; // Debug message: echo '<p>' .mysqli_error($dbc) .'<br /><br />Query: ' .$q . '</p>'; } // End of IF. mysqli_close($dbc); // Close the database. // 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 b/>\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } //End of if (empty($errors)) IF. } // End of mail 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'); ?> Thanks inanticipation Paul
  11. Thanks for the reply. I had a play around with it and it was the code. I am using Dreamweaver and running on a local server xammp. In Dreamweaver the image has to be relative to the root and I had it relative to the document. The change in the code was: <div id="header"><img src="images/header-2.jpg" width="775" height="108" alt="Header Image" /></div> <div id="header"><img src="/scripts/includes/images/header-2.jpg" width="775" height="108" /></div> Its working fine now, However as I am going through the book I'm sure I will be back with something else i can't quite figure out Thanks Paul
  12. I have just completed the headers and footers section of the book. I created the index page as instructed and all works well, except I have an image on the header page that shows when I publish the header page but when I publish the index page I just get an empty box with a little red cross in the top left hand corner. Would be obliged if someone could take a look and let me know what I did wrong. I have included the Header, Footer and Index pages. Thanks Paul Header Page <!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><?php echo $page_title; ?></title> </head> <body> <div id="header"><img src="images/header-2.jpg" width="775" height="108" alt="Header Image" /></div> <div id="navigation"> <ul> <li><a href="index.php">Home Page</a></li> <li><a href="calculator.php">Calculator</a></li> <li><a href="dateform.php">Date Form</a></li> <li><a href="#">Link Four</a></li> <li><a href="#">Link Five</a></li> </ul> </div> <div id="content"><!-- Page Specific Content goes Here. --> <!-- Script 3.2 - header.html --> Footer Page <div id="footer"> <p>"The Recruitment Services Bureau, Lytham, Lancs".<br> All Rights reserved, Job Vacancies Blackpool, Lancashire.</div></p> <p><strong>[<a href="#">Privacy Policy</a>] [<a href="#">Links</a>] [<a href="#">Site Map</a>] [<a href="#">Website Disclaimer</a>]</strong></span></div> </body> </html> Index Page <?php # Script 3.4 - index.php $page_title = 'Welcome to this site!'; include ('includes/header.html'); ?> <h1>Content Header</h1> <p>This is where the page specific content goes. This section, and the corresponding header, will change from one page to the next.</p> <?php include ('includes/footer.html'); ?>
  13. Now I'm confused. I spent hours looking at this code. I closed Dreamweaver and was just about to go to bed, but then thought I would try it in IE.It worked fine so I tried it again in firefox and it worked fine in that as well. Computers hey!
  14. I am having a problem with the Gender variable on a form. When I test the form in the browser the message works fine ie "Good Day, Sir", However when I change the radio button to select Female I get the message "You have not selected your gender". I have checked and double checked the code and it's exactly as it is written in the book. I have pasted the HTML form code and the Handle Form.php code. Could someone take a look and see if I'm missing something please. <!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>Simple HTML Form</title> </head> <body> <!--Script 2.1 - Form HTML --> <form action="handle_form.php" method="post"> <fieldset><legend>Enter your information in the form below:</legend> <p><b>Name:</b> <input type="text" name="name" size="20" maxlengh="40" /></p> <p><b>Email Address:</b> <input type="text" name="email" size="20" maxlengh="40" /></p> <p><b>Gender:</b> <input type="radio" name="gender" value="M" /> Male <input type="radio" name="gender" value="F" />Female</p> <p><b>Age:</b> <select name="age"> <option value="0-29">under30</option> <option value="30-60">Between 30 and 60 </option> <option value="60+">Over 60</option> </select></p> <p><b>Comments:</b> <textarea name="comments" rows="3" cols="40"></textarea></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit my Information" /></div> </form> </body> </html> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- <!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>Form Feedback</title> </head> <body> <?php # Script 2.3 - handle_form.php #2 // Create a shorthand for the form data: $name = $_REQUEST['name']; $email = $_REQUEST['email']; $comments = $_REQUEST['comments']; // create the $gender variable: if (isset($_REQUEST['gender'])) { $gender = $_REQUEST['gender']; } else { $gender = NULL; } // Print the submitted information: echo "<p>Thank you, <b>$name</b>, For the following comments:<br /> <tt>$comments</tt></p> <p>We will reply to you at <i>$email</i></p>\n"; // Print a message based upon the gender value: if ($gender == 'M') { echo '<p><b>Good Day, Sir!</b></p>'; } elseif ($gender == 'F') { echo '<p><b>Good Day, Madam</b></p>'; } else { // No gender selected. echo '<p><b>You forgot to enter your gender!</b></p>'; } ?> </body> </html>
  15. Thank's margaux I cleared out the cache and all the error messesages came up when I broke the form on purpose. The only problem I have now is when I post the form I get the error "The email address and password do not match those on file" (When I know for a fact that they do). Ive tried entering the data using the "register.php" and also directly into the database but I still get this error message. David Thanks for your input. The tip about quoting out will come in really usefull. I'm new to this game so any little tips or help is greatly apreciated, thanks
  16. I am working my way through the php6 & mysql5 book. I have come across a problem. I am at the “password.php” section. When I test the form in my browser and I press the change password button without filling in the form I get “Error!” If I then fill out my email address but don’t put the correct password in I still just get the “Error!” message with no notification of what I have done wrong. If I then complete the form correctly and press the change password button I just get a blank page with the header and footer displayed. I have been through the code a few times and can’t see where I have gone wrong. I then decided to download the completed lessons from the website and tested the form from the zip file. This form behaves in exactly the same way as mine does. I have completed the register exercise and the register.php works fine. I have enclosed the script if it's any help: <?php # Script 8.7 - password.php // This page lets a user change their password. $page_title = 'Change Your Password'; include ('includes/header.html'); // Check if the form has been submitted: if (isset($_POST['submitted'])) { require_once ('C://xampp/store/mysqli_connect.php'); // Connect to the db. $errors = array(); // Initialize an error array. // 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 the current password: if (empty($_POST['pass'])) { $errors[] = 'You forgot to enter your current password.'; } else { $p = mysqli_real_escape_string($dbc, trim($_POST['pass'])); } // Check for a new password and match // against the confirmed password: if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'Your new password did not match the confirmed password.'; } else { $np = mysqli_real_escape_string($dbc, trim($_POST['pass1'])); } } else { $errors[] = 'You forgot to enter your new password.'; } if (empty($errors)) { // If everything's OK. // Check that they've entered the right email address/password combination: $q = "SELECT user_id FROM users WHERE (email='$e' AND pass=SHA1('$p') )"; $r = @mysqli_query($dbc, $q); $num = @mysqli_num_rows($r); if ($num == 1) { // Match was made. // Get the user_id: $row = mysqli_fetch_array($r, MYSQLI_NUM); // Make the UPDATE query: $q = "UPDATE users SET pass=SHA1('$np') WHERE user_id=$row[0]"; $r = @mysqli_query($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Print a message. echo '<h1>Thank you!</h1> <p>Your password has been updated. In Chapter 11 you will actually be able to log in!</p><p><br /></p>'; } else { // If it did not run OK. // Public message: echo '<h1>System Error</h1> <p class="error">Your password could not be changed due to a system error. We apologize for any inconvenience.</p>'; // Debugging message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // Include the footer and quit the script (to not show the form). include ('includes/footer.html'); exit(); } else { // Invalid email address/password combination. echo '<h1>Error!</h1> <p class="error">The email address and password do not match those on file.</p>'; } } else { // Report the errors. echo '<h1>Error!</h1> <p class="error">The following error(s) occurred:<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. mysqli_close($dbc); // Close the database connection. } // End of the main Submit conditional. ?> <h1>Change Your Password</h1> <form action="password.php" method="post"> <p>Email Address: <input type="text" name="email" size="20" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p> <p>Current Password: <input type="password" name="pass" size="10" maxlength="20" /></p> <p>New Password: <input type="password" name="pass1" size="10" maxlength="20" /></p> <p>Confirm New Password: <input type="password" name="pass2" size="10" maxlength="20" /></p> <p><input type="submit" name="submit" value="Change Password" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('includes/footer.html'); ?>
×
×
  • Create New...