Jump to content
Larry Ullman's Book Forums


  • Posts

  • Joined

  • Last visited

konfused's Achievements


Newbie (1/14)



  1. From several of Larry Ullmann’s books in 2013 I was able to create 8 successful databases using XAMPP. On one of my Windows 10 computers I downloaded the latest version 7 of XAMPP for PHP7 and MySQL 8 and I am no longer able to run databases because of the following error message: Could not connect to MySQL: Access denied for user 'horatio'@'localhost' (using password: YES) I assume that my 2012 code is now out of date. I would be most grateful if you would let me know what the code should now be. In 2013 the successful mysqli_connect.php code was as follows: <?php // This provides the information for accessing the database. DEFINE ('DB_USER', 'horatio'); DEFINE ('DB_PASSWORD', 'hmsvictory'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'simpleIdb'); // Make the connection: $dbcon = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); // Set the encoding... mysqli_set_charset($dbcon, 'utf8'); ?> The page that interacts with mysqli_connect.php contains the following linking code: if (empty($errors)) { // If everything's OK. // Register the user in the database... require ('./mysqli_connect.php'); // Connect to the db. I am able to create datebases and tables using the latest phpmyadmin included in XAMPP 7.
  2. Yes I did use a semicolon, I have found the answer, This works for all browsers '
  3. Using text such as "On the book's last page..." All modern browsers accept the entity &apos: but IE 8 does not. IE 8 displays the actual entity. If I use an actual apostrophe, it looks fine in IE8, but the modern browsers show a strange symbol. Is there a way of including an apostrophe in an HTML5 page with PHP includes that will display OK in IE8 and also in modern browsers? The page is saved as a PHP page.
  4. Thank you Larry and HartleySan, 95% of my students use Windows but I also need to advise the 5% who use Macs. I tried the link provided by HartleySan but I think the command line approach is too daunting for my absolute beginners classes. I will probably have to risk downloading "Image Resizer" into an old computer so that my other machines won't be infected. Best wishes Konfused
  5. I have several of Larry's books but this does not directly relate to any of them. I hope that is OK I teach web design to beginners and would like to recommend a free, stand-alone image optimiser to my students . I tried downloading one from the internet and my computer was infected very badly with the "mysearchdial.com" search bar. It took me a whole day using my anti-virus program and three anti-malware programs to get rid of this pest. I am now very wary of trying other free programs for resizing and compressing images for web sites. Please would you recommend a bug free program. "Image Resizer" has been recommended, can you advise me if that is safe? Best wishes
  6. Thank you Antonio MS Word will save documents as PDFs. I will try that.
  7. I publish monthly minutes for a town council web site. I use an "index_of_minutes.php" page with links to the individual minutes which are Word documents. Although I set each document to CHMOD 644, users can save the documents and alter them before printing them. How can I prevent this? Making the documents read-only does not seem to help.
  8. Hello Hartley Stan I tried your last suggestion but no messge was contained in the email. I think the email instructions should be removed from the post.php page and they should appear in the process_post.php file. I don't know the best way of including the email code into the process_post.php file, I would be grateful for your advice. Here is the process_post.php file <?php // Start the session session_start(); // Include the login functions to check for errors require ( 'login_functions.php' ) ; // If users are not logged in, redirect them if ( !isset( $_SESSION[ 'member_id' ] ) ) { load() ; } //Connect to the database require ( 'mysqli_connect.php' ) ; // Has the form been submitted? if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Check that the user has entered a subject and a message if ( empty($_POST['subject'] ) ) { echo '<p>You forgot to enter a subject.</p>'; } if ( empty($_POST['message'] ) ) { echo '<p>You forgot to enter a message.</p>'; } if ( !empty( $_POST['message'])) { $message = mysqli_real_escape_string( $dbcon, strip_tags(trim( $_POST['message'] )) ) ; } // If successful, insert the post into the database table if( !empty($_POST['subject']) && !empty($_POST['message']) ) { //Make the insert query $q = "INSERT INTO forum(uname, subject, message, post_date) VALUES ('{$_SESSION['uname']}', '{$_POST['subject']}','$message',NOW() )"; $result = mysqli_query ( $dbcon, $q ) ; // If it fails display an error message if (mysqli_affected_rows($dbcon) != 1) { echo '<p>Error</p>'.mysqli_error($dbcon); } else { load('forum.php'); } // Close the database connection mysqli_close( $dbcon ) ; } } // Create a link back to the forum page. //echo '<p><a href="forum.php">Forum</a>' ; //include ( 'includes/footer.php' ) ; ?>
  9. I have just realized why the message is not included. The code sends the email the immediately the page is loaded and before the user has time to enter a message into the form. An if clause is needed before the email is sent but I would like some help with this, Please would you suggest some code that will do the trick? Best wishes Konfused
  10. Reply to Hartley San Many thanks for you prompt reply, sadly with neither solution the email contain the message, this is what I receive: with the firts solution I get: mechanic7 added the following message: with the second solution I get: $user added the following message: The message is inserted into the database table so I think I must be assigning it incorrectly for the email. I repeat the relevant part of the better code hoping that you can spot the problem echo '<form action="process_post.php" method="post" accept-charset="utf-8"> <p>Choose the Subject: <select name="subject"> <option value="Category One">Category One</option> <option value="Category Two">Category Two</option> </select></p> <p>Message:<br><textarea name="message" rows="5" cols="50"></textarea></p> <p><input name="submit" type="submit" value="post"></p> </form>'; include ( 'includes/footer.php' ) ; //posting an entry into the database table automaticlally sends a message to the forum moderator // Assign the subject $subject = "Posting added to message board"; $user = isset($_SESSION['uname']) ? $_SESSION['uname'] : ""; //$message="message"; $message=$_POST['message']; $body = "$user added the following message:\r\n$message"; mail("me@myisp.co.uk", $subject, $body, "From:admin@myisp.co.uk\r\n");?>
  11. The following code inserts a message into my message board, that part functions with no problem. It is then supposed to send me an email to alert me that a message has been sent to me. I receive the email with the alert saying posting added by the user but the message just contains the word message. I am obviously doing something silly, <?php session_start() ; // Redirect user if he is not logged in if ( !isset( $_SESSION[ 'member_id' ] ) ) { require ( 'login_functions.php' ) ; load() ; } ?> <!doctype html> <html lang=en> <head> <title>The form for posting messages</title> <meta charset=utf-8> <link rel="stylesheet" type="text/css" href="forum.css"> <style type="text/css"> #tab-navigation ul { margin-left:85px; } form { padding-left:215px; } </style> </head> <body> <div id='container'> <?php // The form for posting messages include ( 'includes/header_post.php' ) ; echo '<h2>Post a Message</h2>'; // Display the form fields echo '<form action="process_post.php" method="post" accept-charset="utf-8"> <p>Choose the Subject: <select name="subject"> <option value="Category One">Category One</option> <option value="category Two">Category Two</option> </select></p> <p>Message:<br><textarea name="message" rows="5" cols="50"></textarea></p> <p><input name="submit" type="submit" value="post"></p> </form>'; include ( 'includes/footer.php' ) ; //posting an entry into the database table automaticlally sends an email to the forum moderator // Assign the the variables $subject = "Posting added to message board"; $user = isset($_SESSION['uname']) ? $_SESSION['uname'] : ""; $message='message'; $body = "Posting added by . $user . $message"; mail("me@myisp.co.uk", $subject, $body, "From:me@myisp.co.uk\r\n");?> </div> </body> </html please would you enlighten me.
  12. Many thanks Larry and StephenM When you both reassured me that the code I posted was correct, I deduced that there must be a difference between the code I posted and the test file I was using. Sure enough, instead of $q = "SELECT ; I had written Sq = "SELECT; The difference between a dollar sign and a capital S made all the difference. Thanks for pointing me in the right direction, all is well now. Best wishes
  13. Hello again Antonio I am not sending an email. The code is part of a user registration page. The two blocks of code (preceded by comments in capitals) are supposed to check whether the email address being registered is already in the database table. It should avoid the possibility of entering duplicate email addresses into the database table. Unfortunately it allows duplicates and I can't see why..
  14. The registration page containing the following code works fine except for one irritating fault. The lines commented in capital letters in the following code are supposed to stop duplicate email entries but they don't. Can you spot the mistake please? <?php require ('mysqli_connect.php'); // Connect to the database. // This code inserts a record into the users table // Has the form been submitted? if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); // Start an array to hold the errors // Check for a title: if (empty($_POST['title'])) { $errors[] = 'You forgot to enter your title.'; } else { $title = mysqli_real_escape_string($dbcon, trim($_POST['title'])); } // Check for a first name: if (empty($_POST['fname'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = mysqli_real_escape_string($dbcon, trim($_POST['fname'])); } // Check for a last name: if (empty($_POST['lname'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = mysqli_real_escape_string($dbcon, trim($_POST['lname'])); } // 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 it against the confirmed password: if (!empty($_POST['psword1'])) { if ($_POST['psword1'] != $_POST['psword2']) { $errors[] = 'Your two passwords did not match.'; } else { $p = mysqli_real_escape_string($dbcon, trim($_POST['psword1'])); } } else { $errors[] = 'You forgot to enter your password.'; } if (empty($_POST['uname'])) { $errors[] = 'You forgot to enter your secret username.'; } else { $uname = trim($_POST['uname']); } // Check for an membership class if (empty($_POST['class'])) { $errors[] = 'You forgot to choose your membership class.'; } else { $class = trim($_POST['class']); } // Check for address1: if (empty($_POST['addr1'])) { $errors[] = 'You forgot to enter your address.'; } else { $ad1 = mysqli_real_escape_string($dbcon, trim($_POST['addr1'])); } // Check for address2: if (!empty($_POST['addr2'])) { $ad2 = mysqli_real_escape_string($dbcon, trim($_POST['addr2'])); }else{ $ad2 = NULL; } // Check for city: if (empty($_POST['city'])) { $errors[] = 'You forgot to enter your City.'; } else { $cty = mysqli_real_escape_string($dbcon, trim($_POST['city'])); } // Check for the county: if (empty($_POST['county'])) { $errors[] = 'You forgot to enter your county.'; } else { $cnty = mysqli_real_escape_string($dbcon, trim($_POST['county'])); } // Check for the post code: if (empty($_POST['pcode'])) { $errors[] = 'You forgot to enter your post code.'; } else { $pcode = mysqli_real_escape_string($dbcon, trim($_POST['pcode'])); } // Check for the phone number: if (!empty($_POST['phone'])) { $ph = mysqli_real_escape_string($dbcon, trim($_POST['phone'])); }else{ $ph = NULL; } if (empty($errors)) { // If everything is OK //DETERMINE WHETHER THE EMAIL ADDRESS HAS ALREADY BEEN REGISTERED $q = "SELECT user_id FROM users WHERE email = '$e'"; $result = mysqli_query ($dbcon, $q); if (mysqli_num_rows($result) == 0){//The mail address has not been registered already therefore... // Register the user in the users table $q = "INSERT INTO users (user_id, title, fname, lname, email, psword, registration_date, uname, class, addr1, addr2, city, county, pcode, phone, paid) VALUES (' ', '$title', '$fn', '$ln', '$e', SHA1('$p'), NOW(), '$uname', '$class', '$ad1', '$ad2', '$cty', '$cnty', '$pcode', '$ph', '$pd' )"; $result = @mysqli_query ($dbcon, $q); // Run the query. if ($result) { // If it ran OK. header ("location: register-thanks.php"); exit(); } else { // If it did not run OK // Error message: echo '<h2>System Error</h2> <p class="error">Registration failed because of a system error. We apologize for the inconvenience.</p>'; // Debugging message: echo '<p>' . mysqli_error($dbcon) . '<br><br>Query: ' . $q . '</p>'; } // End of if ($result) mysqli_close($dbcon); // Close the database connection // Include the footer and stop the script include ('footer.php'); exit(); }else{//IF THE EMAIL ADDRESS IS ALREADY REGISTERED echo '<p class="error">The email address is not acceptable because it is already registered</p>'; } } else { // Report the errors. echo '<h2>Error!</h2> <p class="error">The following error(s) occurred:<br>'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br>\n"; } echo '</p><h3>Please try again.</h3><p><br></p>'; }// End of if (empty($errors)) } // End of the main Submit conditional. ?>
  15. Many thanks StephenM for your prompt reply, I will now look at the code more carefully.
  • Create New...