Jump to content
Larry Ullman's Book Forums


  • Posts

  • Joined

  • Last visited

ericp's Achievements


Newbie (1/14)



  1. Perhaps, my English is not sufficient enough to explain the file system that I organized, or I chose the wrong word to explain it. Yes, you are right, and I also beleived so. So, according to my file organization, do you have any idea about how to trigger/call the my_error_handler( ) function to handle the errors, which is established in the configuration script? For example, how can we call it in the index.php page (view all posts created and posted by all users of the forum) in case that we have any error in the query ($q ="SELECT ...";) within the page's content section, while the configuration file has already been in the header section? Sorry if my explanation is still vague to you.
  2. My mistake, indeed, as I called both the mysqli_connect.php and the mysqli_connect_OOP.php in the config.inc.php file at the same time. One of them should have been called once.
  3. Sorry for late response, but I was really busy in the last few weeks. Ok. To be short, let me briefly show you the codes of my pages as follows: 1/ Index.php page: <?php Include the header include ('includes/header.html'); //codes to show/echo the page content <p> bla bla </p> //Include footer include ('includes/footerl.html'); ?> 2/ The header.html file: <?php //start a session session_start(); // Include the configuration file: require ('includes/config.inc.php'); // Get the words for this language: require (MYSQL); //include lang choice require ('includes/languages.inc.php'); ?> <!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> <title><?php echo $page_title; ?> </title> </head> <body> <p> neccessary items for header part. </p> 3/ footer.html file </body> </html> <?php // Flush the buffered output. ob_end_flush(); ?> In the header.html file, you can see that I included the config.inc.php, which is the copied one of yours, and the languages.inc.php, which stores and retrieves the language ID as your script 17.1.php does. This languages.inc.php does not need the database connection because the database connection had been included in the config.inc.php (define ('MYSQL', './database/mysqli_connect.php');, which goes before this file in the header.html In my every query to SELECT, INSERT INTO, DELETE, ect in the main pages such as register.php, view_posts.php, ect, I include the the error trigger ( 'or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); ') right in the $result=....; And I try testing by purposedly adding error into the code so that it would send to my assigned email address, but it didn't. The error returned directly in browser. Can you help? Thanks a lot!
  4. Yes, you are right. And I also tried it. You know what? When i define the location of the MySQL connection script in the config.inc.php, using script 16.1, along with the script mysqli_connect.php in Ch 18 for it, the error occurs like this '... on line 15: Constant LIVE already defined'. I know, it's an error!. Then, I commented out the mysqli_connect.php, it requires me to RE-CODE all the files that I used Procedural so far which would take me lots of time. Do you have any suggestion? because I have to switch to OOP gradually one by one, and the config.inc.php is included in the hear.html file, but not in seperate files. Or should I switch to OOP just because of the point in your book saying that it may be more secure and faster? Thanks
  5. I have made no change to the codes. As my header.html has two languages, I have to include the config.inc.php because the config.inc.php file defines the location of the MySQL connection script, mysqli_connect.php. Without this step, my header.html cannot function and cannot print the languages repectively, either. The difference between yours and mine is that you include the config.inc.php in the individual .php files along with the code of 'require (MYSQL); ' when you make the query for the tasks; whereas I include them in the header file only. The similarity between yours and mine is that we both use the error trigger ( 'or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); ') right in the $result=....; In my opinion, if we include the config.inc.php, the error handler should(must) be called because it has been really really included in it. Everything goes smoothly for me. However, the question in my head is that why does it not send the errors, if any as i test the writing scripts, to my defined email, but print it on the browser as if the error_handler function in the config.inc.php file was ignored. Does it technically ignore the error_handler function if it's not included directly in the writing file, to your coding experience? or what? I am confused/concerned about whether php programming language itself ignores the function that is included in the 'included' file?
  6. Hi everyone, As my header.html included file needs to connect to the dadabase for retrieving data, I have to include the config.inc.php script (18.3) in it, but not the individual file, e.g., register.php, etc, as per the chapter 18 outlines. You know, the errors directly display on the web browser instead of being sent to the defined email. Do you know why? And how can I get it sent to as per the my_error_handler function triggers? Note: In my .ini file, I changed the error_reporting to E_ALL, and log_errors to on , and I am not sure if these changes caused the problem or not? Can you help? Thanks
  7. Hi all, Can anyone help re-code the configuration file, script 18.3, using the prepared Statement Performance so that it can be compatible with the OOP (Object-Oriented Programming) MySQL connection script ((Script 16.1), please? Thanks
  8. I luckily figured it out. The problem is at html design which causes the bug. Sorry for the confusion. Can you help me delete this entry, please?
  9. Hi Larray and all, I have edited this script to fit my project, which I cut off the first name and last name. I added the username field which looks like this: <form action="" method="post"> <fieldset> <legend>Sign Up </legend> <label>Choose a username</label> <input type="text" name="username" size="20" maxlength="20" value=" <?php if (isset($trimmed['username'])) echo $trimmed['username']; ?>" /> <label>Email</label> <input type = "text" name="email" size="30" maxlength="60" value ="<?php if(isset($trimmed['email'])) echo $trimmed['email']; ?>" /> <label>Select a password</label> <input type="password" name="password1" size="20" maxlength="20" value="<?php if(isset($trimmed['password1'])) echo $trimmed['password1']; ?>" /> <label>Confirm password</label> <input type="password" name="password2" size="20" maxlength="20" value="<?php if(isset($trimmed['password2'])) echo $trimmed['password2']; ?>" /> <input type = "submit" name="submit" value="Sign Up "/> </fieldset> </form> I followed the script 18.6 strickly, plus do the username validation like this (of course, I also initiate the $errors = array(); too: //validate the username if (preg_match('/^\w\S{2,20}$/', $trimmed['username']) ) { $u = mysqli_escape_string($dbc, $trimmed['username']); } else { $errors[] = 'Please enter a username'; } Assume that other variable validations are okay. I code like this: if($u && $e && $p){//OK // Check for unique username and email $q = "SELECT user_id from users where username='$u' AND email='$e'"; $r = mysqli_query($dbc, $q) or die("MySQL error: " . mysqli_error($dbc) . "<hr>\nQuery: $q"); if(mysqli_num_rows($r) == 0 ){ // Create the activation code $a = md5(uniqid(rand(), TRUE)); //Defined variable for language ID $l = $_SESSION['lid']; //retrieved already in the header //Insert into database, table users $q = " INSERT INTO users (lang_id, username, pass, email, active, registration_date) VALUES ('$l','$u', SHA1('$p'), '$e', '$a', NOW() ) "; $r = mysqli_query($dbc, $q) or die("MySQL error: " . mysqli_error($dbc) . "<hr>\nQuery: $q"); if (mysqli_affected_rows($dbc) == 1) { // everything's ok //Send the email: $body = "Thank you for your registration at askpro.com. To activate your account, please click on the link below \n\n"; $body .= BASE_URL. 'activate.php?e='.urlencode($e). "&a=$a"; mail($trimmed['email'], 'Registration Confirmation', $body, 'From: info@website.com'); //Finish the page echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>'; include ('includes/footer.html'); // Include the HTML footer. exit(); // Stop the page. } else { $errors[]='You could not be registered due to a system error. We apologize for any inconvenience.'; } }else{ $errors[] = 'either the username or email has already been registered. If you have forgotten your password, use the link above to have your password sent to you.</'; } }else { // If one of the data tests failed. echo 'Error:<br />'; foreach ($errors as $msg) { // Print each error. echo "- $msg <br />"; } $error[] = 'Please try again'; } } The question is that: -/ When I enter value and click the 'sign up' button with the intention that I enter a duplicate email, i.e., email@website.com, it returned error like this: MySQL error: Duplicate entry 'email@website.com ' for key 3 --------------------------------------------------------- Query: SELECT user_id FROM users WHERE (username = 'dsfdsf' AND email = 'e') -/ Then I change the query to: $q = "SELECT user_id from users where username='$u' OR email='$e'"; It returns NO error, but it does not insert anything into the database, and no 'thank you message' is printed. Can you help me to figure this out? Am I doing anything wrong? Thank you. P/S: This is my users table:
  10. I just had a problem with charset utf8 for my script 17.7.php I add this into my connection script (mysqli_connect.php) as per the book guilde mysqli_set_charset($dbc, 'utf8'); And my live server is shared linux with Godaddy.com. The storage engine i am using is MySIAM, and the collocation is 'utf8_general_ci' and the PHP Version is 5.3.24 The form is also coded to accept utf8 one more time like this: <form action="" method="post" accept-charset="utf-8"> And the header .html file is also the same as the book guilde which includes this: header ('Content-Type: text/html; charset=UTF-8'); When I validate the form, using htmlentities for the textarea field as $body = htmlentities($_POST['body']); When I enter my language, Vietnamese, i.e. đình, it is converted to something like Ä If I exclude the htmlentities function, it becomes normal. So, How can I validate it using the htmlentities function for other languages beside English, as htmlentities will protect the form from hacking or so? or should I use another function? Thank you
  11. Sorry, but can you help with the solution for it with the while loop as of the example script 17.1 in the book or my above script? Thank you very much.
  12. Hi HarleySan, This is my form: <?php echo '<form action="" method="get"> <select name="lid" id="sel_lang"> <option value="0">' . $langs['lang'] . '</option>'; // Retrieve all the languages... $q = "SELECT lang_id, lang_others FROM languages ORDER BY lang_eng ASC"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo "<option value=\"$menu_row[0]\">$menu_row[1]</option>\n"; } } mysqli_free_result($r); echo '</select> <input name="submit" type="submit" value="'. $langs['go']. '" /> </form>'; mysqli_close($dbc); //Close the database connection. ?> Can you help, pls?
  13. Hi, Anyone can help to code how to add the sticky value for the drop-down chosen language after a user hits the the 'submit' button so that the default value won't return to 'language' ($words ['language']) value, please? Thanks in advance, Eric
  • Create New...