Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'php'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Found 183 results

  1. I am trying to implement a search feature to a forum I am creating and I want users to be able to search through posts. So far users type in the search terms in a form, and they go through to my $_GET['terms']. The problem is that the IN BOOLEAN MODE search only returns posts that start with or end with one of the search terms users type into the form. I want it so that the search can also return phrases that are within posts, not necessarily starting or ending with. I have tried the boolean mode operators in all sorts of ways but it doesn't work. Is it possible to use fulltext searches in this way, or should I try a different method. Here is my Mysql query I am using: $terms = mysqli_real_escape_string($dbc, htmlentities(strip_tags($_GET['terms']))); $q = "SELECT m.message, m.posted_on, s.thread_id, s.subject FROM posts AS m LEFT JOIN threads AS s USING (thread_id) WHERE MATCH (message, subject) AGAINST('$terms*' IN BOOLEAN MODE)";
  2. I have built a forum for my own website thanks to the forum example in this book in chapter 17. Now I want the capability to search through posts and show the results of the search. I modified the search.php script included in the course files. I tested it and it doesn't work properly, the $_GET['terms'] doesn't get set when I type in search terms and click search. I tested it by echoing out 'hello' after the isset($_GET['terms']) . I don't know why it isn't set though, in the address bar it is written search.php?terms=test&submit=Submit <?php # Script 17.8 - search.php // This page displays and handles a search form. // Include the HTML header: // Show the search form: echo '<form action="search.php" method="get" accept-charset="utf-8"> <p><em>Search </em>: <input name="terms" type="text" size="30" maxlength="60" '; // Check for existing value: if (isset($_GET['terms'])) { echo 'value="' . htmlspecialchars($_GET['terms']) . '" '; } // Complete the form: echo '/><input name="submit" type="submit" value="' . $words['submit'] . '" /></p></form>'; if (isset($_GET['terms'])) { // Handle the form. echo 'hello'; // Clean the terms: $terms = mysqli_real_escape_string($dbc, htmlentities(strip_tags($_GET['terms']))); // Run the query... $q = "SELECT message FROM posts WHERE MATCH (message) AGAINST ('test' IN BOOLEAN MODE)"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { $row = mysqli_fetch_array($r, MYSQLI_ASSOC); echo '<h2>Search Results</h2>'; echo '<p>' . $row['message'] . '</p>'; } else { echo '<p>No results found.</p>'; } } ?>
  3. I am working on a site, and using the scripts in this book. I keep getting the error this page has been accessed in error. The script should insert a record into the database, instead it doesn't do any validation or anything else, it just gives the error message. I thought it might be a problem with the database but I can't find the problem. Any ideas.
  4. I want to integrate the forum example in the book into my website, except I would modify it so that I could have multiple forums with different topics on my site. What I want to know is what columns and tables do you think I should add to my forum database. To add to the example in the book, I thought of creating a new forums table, and in it having the forum_id column, as well as the thread_id foreign key column. I am new at this so if you have any suggestions at populating my forums table that would be great.
  5. I am creating a site using the registration system in chapter 18, and I am using the output buffer on every page, the ob_start() is included in every page via the header.html file. In the book it says that if we use the output buffer we won't get headers already sent error messages. But I just tested it and put a space before the starting <?php tag. And I got the following error. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/ why does it give an error message.
  6. I have just typed out index.php for chapter 17, and the language drop down menu displays funny characters instead of the language specific letters. I typed the scripts as shown in the book. How can I debug this, is it my Xampp settings, I checked and it says the language is set to US in Xampp. In the book it says to save my page using utf-8 encoding. I don't know if that is the problem, I just saved my index.php page with the name index.php, in dreamweaver I don't see an option for the encoding to use for the page. In my header file the encoding is set to utf-8 and that file is included in index.php, so won't that do it.
  7. I have bought and read larrys php for the web 4th edition, and php and javascript. I am having trouble with the example in chapter 11 of php and javascript .. accessing a javascript function form inside php. can somesone send me an email so I can describee the problem. I spend all morning typing the question in notepad but for some reason I cant copy/paste it to forum box .. tried ctrl/c-ctrl/v .. edit-copy/edit-paste .. right click copy/paste .. nothing works at 73 with arthritus in my hands, if I try to type is again it will contain typping errors. jerry gentry .. www.wa0h.com .. jerrywa0h@sbcglobal.net
  8. In this book in chapter 2 script 2.4 index.php. It says to include the configuration file: require('./includes/config.inc.php'); How can you reference a file with ./, shouldn't it be ../ I tried it and it doesn't work. Is this a mistake in the book?
  9. My show_image.php script is not working. When I click on the links the popup window comes up but the images don't display, only the unavailable.jpg image displays. I checked the uploads folder and it seems ok. I am using the downloaded script from this site to make sure the code is ok. For images.php, and upload_image.php, and functions.js, I am also using this site's scripts. I tried to see the source code from the popup window and there is nothing it is blank. Here is the show_images.php code. <?php # Script 11.5 - show_image.php // This page displays an image. $name = FALSE; // Flag variable: // Check for an image name in the URL: if (isset($_GET['image'])) { // Make sure it has an image's extension: $ext = strtolower ( substr ($_GET['image'], -4)); if (($ext == '.jpg') OR ($ext == 'jpeg') OR ($ext == '.png')) { // Full image path: $image = "../../../../uploads/{$_GET['image']}"; // Check that the image exists and is a file: if (file_exists ($image) && (is_file($image))) { // Set the name as this image: $name = $_GET['image']; } // End of file_exists() IF. } // End of $ext IF. } // End of isset($_GET['image']) IF. // If there was a problem, use the default image: if (!$name) { $image = 'images/unavailable.png'; $name = 'unavailable.png'; } // Get the image information: $info = getimagesize($image); $fs = filesize($image); // Send the content information: header ("Content-Type: {$info['mime']}\n"); header ("Content-Disposition: inline; filename=\"$name\"\n"); header ("Content-Length: $fs\n"); // Send the file: readfile ($image);
  10. In Chapter 11 in the sending email script called email.php, the $_POST['name'] and $_POST['comments'] in the $body variable are wrapped in curly braces. Why are there curly braces around them. See the code below. if ($_SERVER['REQUEST_METHOD'] == 'POST'){ if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['comments'])){ $body = "Name: {$_POST['name']}\n\nComments: {$_POST['comments']}"; $body = wordwrap($body, 70); } }
  11. I am building a website after reading this book, and I am having trouble with the selected="selected" part of a select menu. Nothing is getting selected. When I click on submit form it goes through but the item I selected isn't being selected in my database. In the following code, the problem lies in the following section: where the select menu is, but I can't get it to work. help would be appreciated. <?php $optionarray = array(3 => 'Children & Family', 4 => 'Home Business', 5 => 'Advertising', 6 => 'Affiliate Programs', 7 => 'Art & Photography', 9 => 'Beauty & Jewelry', 10 => 'Blogging', 11 => 'Books, Literature', 12 => 'Business & Finance', 13 => 'Computer Games', 14 => 'Computing', 15 => 'Dating & Relationships', 16 => 'Directories', 17 => 'Education', 18 => 'Electronics', 19 => 'Entertainment', 20 => 'Environment', 21 => 'Flowers', 22 => 'Food, Drink', 23 => 'Forums, chat rooms', 24 => 'Free Stuff', 25 => 'Gifts & Shopping', 26 => 'Health', 27 => 'Humor', 28 => 'Interior Design', 29 => 'Internet Marketing', 30 => 'Miscellaneous', 31 => 'Music', 32 => 'Pets', 33 => 'Real Estate', 34 => 'Religion & Spirituality', 35 => 'Science', 36 => 'Sports', 37 => 'Stocks & Trading', 38 => 'Travel', 39 => 'Vehicles', 40 => 'Web Design', 41 => 'Web Hosting', 42 => 'Work At Home', 43 => 'Psychology'); echo '<form action="edit_your_sites.php" method="post"><select name="SiteTypeID"><option value="">Select a Category</option>'; foreach ($optionarray as $key => $value){ echo '<option value="$key"'; if (isset($_POST['SiteTypeID']) && ($_POST['SiteTypeID'] == '. $key . ')) echo 'selected="selected">'; echo $value . '</option>'; } echo '</select>'; ?> <?php $page_title = 'Edit Your Account'; include ('includes/header.html'); include ('includes/functions.php'); include ('includes/config.inc.php'); if (isset($_GET['id']) && is_numeric($_GET['id'])){ $id = $_GET['id']; } elseif (isset($_POST['id']) && is_numeric($_POST['id'])) { $id = $_POST['id']; } else { echo '<p class="error">This page has been accessed in error.</p>'; include ('includes/footer.html'); exit(); } if (isset($_SESSION['UserID'])){ require (MYSQL); echo '<div class="text">'; $scrubbed = array_map('spam_scrubber', $_POST); if ($_SERVER['REQUEST_METHOD'] == 'POST'){ if (filter_var($scrubbed['url'], FILTER_VALIDATE_URL)){ $url = mysqli_real_escape_string($dbc, $scrubbed['url']); } else { $url = ""; echo '<p class="error">Please enter a valid url</p>'; } if (!empty($scrubbed['SiteTypeID'])){ $sitetypeid = $scrubbed['SiteTypeID']; } else { $sitetypeid =""; echo '<p class="error">Please select a category</p>'; } if($url && $sitetypeid){ $q = "SELECT UserID, url, SiteID FROM sites WHERE url='$url' AND SiteTypeID='$sitetypeid' AND SiteTypeID!=$id"; $query = mysqli_query ($dbc, $q); if (mysqli_num_rows($query) == 0){ $q = "UPDATE sites SET url='$url', SiteTypeID='$sitetypeid' WHERE SiteID=$id LIMIT 1"; $query = mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1){ echo '<p><b>Your url has been successfully edited</b></p>'; } elseif (mysqli_affected_rows($dbc) == 0){ echo '<p>No new details have been inserted</p>'; } else { echo '<p class="error">The user could not be edited due to a system error. We apologize for any inconvenience.</p>'; // Public message. echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message. } } else { echo '<p><b>That url has already been registered with that category, if you own this site you can change categories if you wish to. Please note that a website cannot be added multiple times in different categories.</b></p>'; } } } ?> <h1>Edit Your Sites</h1><p><b>Do not add duplicate urls, they will be deleted. We only accept family-safe urls. We play fair and expect our members to do the same.</b> </p> <?php $query2 = "SELECT s.SiteTypeID, u.UserID, s.SiteType FROM sitetypes AS s LEFT JOIN sites AS u USING (SiteTypeID) WHERE SiteID=$id"; $mx = mysqli_query($dbc, $query2); if (mysqli_num_rows($mx) ==1){ $row2 = mysqli_fetch_array($mx, MYSQLI_ASSOC); echo '<p>Your site\'s current category is <b>'.$row2['SiteType'] . '</b></p>'; } ?> <?php $optionarray = array(3 => 'Children & Family', 4 => 'Home Business', 5 => 'Advertising', 6 => 'Affiliate Programs', 7 => 'Art & Photography', 9 => 'Beauty & Jewelry', 10 => 'Blogging', 11 => 'Books, Literature', 12 => 'Business & Finance', 13 => 'Computer Games', 14 => 'Computing', 15 => 'Dating & Relationships', 16 => 'Directories', 17 => 'Education', 18 => 'Electronics', 19 => 'Entertainment', 20 => 'Environment', 21 => 'Flowers', 22 => 'Food, Drink', 23 => 'Forums, chat rooms', 24 => 'Free Stuff', 25 => 'Gifts & Shopping', 26 => 'Health', 27 => 'Humor', 28 => 'Interior Design', 29 => 'Internet Marketing', 30 => 'Miscellaneous', 31 => 'Music', 32 => 'Pets', 33 => 'Real Estate', 34 => 'Religion & Spirituality', 35 => 'Science', 36 => 'Sports', 37 => 'Stocks & Trading', 38 => 'Travel', 39 => 'Vehicles', 40 => 'Web Design', 41 => 'Web Hosting', 42 => 'Work At Home', 43 => 'Psychology'); echo '<form action="edit_your_sites.php" method="post"><select name="SiteTypeID"><option value="">Select a Category</option>'; foreach ($optionarray as $key => $value){ echo '<option value="$key"'; if (isset($_POST['SiteTypeID']) && ($_POST['SiteTypeID'] == '. $key . ')) echo 'selected="selected">'; echo $value . '</option>'; } echo '</select>'; ?> <?php $ms = "SELECT UserID, url, SiteID FROM sites WHERE SiteID=$id"; $msp = mysqli_query($dbc, $ms); if (mysqli_num_rows($msp) > 0){ $row = mysqli_fetch_array($msp, MYSQLI_ASSOC); echo '<p>Url:<input type="text" name="url" size="60" maxlength="80" value="' . $row['url'] .'" /><small>You can only add each url once into the database, each url must be unique.</small></p><p><input type="submit" name="submit" value="Edit Site Information!" /><input type="reset" name="reset" value="Clear Form" /> <input type="hidden" name="id" value="' . $id . '" /> </form><p><a href="delete_url.php?id=' . $row['SiteID'] . '"><b>Delete Url</b></a>'; } else { echo '<p class="error">A system error occurred, we apologize for the inconvenience.</p>'; } ?> <?php } else { $url = BASE_URL . 'index.php'; header("Location: $url"); } echo '</div>'; include ('includes/footer.html'); ?>
  12. When I user the instanceof keyword for the Singleton class in Ch07 page 218, it is returning true. See below. // Create a second object to confirm: $TEST = Config::getInstance(); // see what instanceof thinks... if ($TEST instanceof Config) { echo '<pre>$TEST IS instance of Config</p>'; } else { echo '<pre>$TEST IS NOT instance of Config</p>'; } It is echoing that $TEST IS instance of Config. Am I doing something wrong?
  13. After exhausting searching and trying many different things and asking people about the add_print.php script in chapter 19 I am now positive that there are errors in this script. I have tried using the exact script supplied by the author in his working files and the images don't display in my uploads folder, and they also don't show up in my view_print.php page. I put the entire script up on stack overflow and got an answer that partially helped fix this. I however still don't see the images on my view_print pages. The show_image.php isn't doing it's job like it should, and I am using the exact files provided by the author. This is extremely frustrating and time consuming, one would expect the examples to be error free. Here is the fix I got on stack overflow. You need to add a couple lines of code and change one line to actually display the image in your uploads folder. The entire modified script is below. Note that this doesn't entirely fix the problem though, you still don't see the images on the view_print.php page. $path_parts = pathinfo($_FILES["image"]["name"]); $extension = $path_parts['extension']; $id = mysqli_stmt_insert_id($stmt); // Get the print ID. rename ($temp, "../../../uploads/$id.".".$extension"); <?php # Script 19.2 - add_print.php // This page allows the administrator to add a print (product). require ('../../mysqli_connect.php'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form. // Validate the incoming data... $errors = array(); // Check for a print name: if (!empty($_POST['print_name'])) { $pn = trim($_POST['print_name']); } else { $errors[] = 'Please enter the print\'s name!'; } // Check for an image: if (is_uploaded_file ($_FILES['image']['tmp_name'])) { // Create a temporary file name: $temp = '../../../uploads/' . md5($_FILES['image']['name']); // Move the file over: if (move_uploaded_file($_FILES['image']['tmp_name'], $temp)) { echo '<p>The file has been uploaded!</p>'; // Set the $i variable to the image's name: $i = $_FILES['image']['name']; } else { // Couldn't move the file over. $errors[] = 'The file could not be moved.'; $temp = $_FILES['image']['tmp_name']; } } else { // No uploaded file. $errors[] = 'No file was uploaded.'; $temp = NULL; } // Check for a size (not required): $s = (!empty($_POST['size'])) ? trim($_POST['size']) : NULL; // Check for a price: if (is_numeric($_POST['price']) && ($_POST['price'] > 0)) { $p = (float) $_POST['price']; } else { $errors[] = 'Please enter the print\'s price!'; } // Check for a description (not required): $d = (!empty($_POST['description'])) ? trim($_POST['description']) : NULL; // Validate the artist... if ( isset($_POST['artist']) && filter_var($_POST['artist'], FILTER_VALIDATE_INT, array('min_range' => 1)) ) { $a = $_POST['artist']; } else { // No artist selected. $errors[] = 'Please select the print\'s artist!'; } if (empty($errors)) { // If everything's OK. // Add the print to the database: $q = 'INSERT INTO prints (artist_id, print_name, price, size, description, image_name) VALUES (?, ?, ?, ?, ?, ?)'; $stmt = mysqli_prepare($dbc, $q); mysqli_stmt_bind_param($stmt, 'isdsss', $a, $pn, $p, $s, $d, $i); mysqli_stmt_execute($stmt); // Check the results... if (mysqli_stmt_affected_rows($stmt) == 1) { // Print a message: echo '<p>The print has been added.</p>'; // Rename the image: $path_parts = pathinfo($_FILES["image"]["name"]); $extension = $path_parts['extension']; $id = mysqli_stmt_insert_id($stmt); // Get the print ID. rename ($temp, "../../../uploads/$id.".".$extension"); // Clear $_POST: $_POST = array(); } else { // Error! echo '<p style="font-weight: bold; color: #C00">Your submission could not be processed due to a system error.</p>'; } mysqli_stmt_close($stmt); } // End of $errors IF. // Delete the uploaded file if it still exists: if ( isset($temp) && file_exists ($temp) && is_file($temp) ) { unlink ($temp); } } // End of the submission IF. // Check for any errors and print them: if ( !empty($errors) && is_array($errors) ) { echo '<h1>Error!</h1> <p style="font-weight: bold; color: #C00">The following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo 'Please reselect the print image and try again.</p>'; } // Display the form... ?> <h1>Add a Print</h1> <form enctype="multipart/form-data" action="add_print.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="524288" /> <fieldset><legend>Fill out the form to add a print to the catalog:</legend> <p><b>Print Name:</b> <input type="text" name="print_name" size="30" maxlength="60" value="<?php if (isset($_POST['print_name'])) echo htmlspecialchars($_POST['print_name']); ?>" /></p> <p><b>Image:</b> <input type="file" name="image" /></p> <p><b>Artist:</b> <select name="artist"><option>Select One</option> <?php // Retrieve all the artists and add to the pull-down menu. $q = "SELECT artist_id, CONCAT_WS(' ', first_name, middle_name, last_name) FROM artists ORDER BY last_name, first_name ASC"; $r = mysqli_query ($dbc, $q); if (mysqli_num_rows($r) > 0) { while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['artist']) && ($_POST['artist'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } } else { echo '<option>Please add a new artist first.</option>'; } mysqli_close($dbc); // Close the database connection. ?> </select></p> <p><b>Price:</b> <input type="text" name="price" size="10" maxlength="10" value="<?php if (isset($_POST['price'])) echo $_POST['price']; ?>" /> <small>Do not include the dollar sign or commas.</small></p> <p><b>Size:</b> <input type="text" name="size" size="30" maxlength="60" value="<?php if (isset($_POST['size'])) echo htmlspecialchars($_POST['size']); ?>" /> (optional)</p> <p><b>Description:</b> <textarea name="description" cols="40" rows="5"><?php if (isset($_POST['description'])) echo $_POST['description']; ?></textarea> (optional)</p> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit" /></div> </form> </body> </html>
  14. 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:
  15. Hi, I run into trouble sending html email to hotmail and aol address using php mail() function. Gmail and Yahoo are fine. But hotmail and aol are failed to receive anything. Here is my header setting $headers = "From: sales@thtc-usa.com\r\n"; $headers .= "Reply-To: sales@thtc-usa.com\r\n"; $headers .= "Return-Path:sales@thtc-usa.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; any suggestion please?
  16. hello everyone.. i have a form to store values for a model add having rows id name description and one is email to store email for particular entry. Now i want a contact form to send mail for that particular model values... that is to send mail to the owner of particular add.. I able to reuse contact form for that purpose but i fail to fetch saved email id for each add so that any viewer can mail for adds.. How to achive this task?? please help me someone.. let me know the how can i do this?? if any example code will be very useful to me.. Thank you.....
  17. Hi, My product page (output) in HTML is something like this: ProductImage1 ProductImage2 ProductImage3 ProductImage4 Color1 Color2 Color3 Color4 Color2 Color5 Color6 What I'm trying to do is when I hover my mouse over any color above, an original (main) image of ProductImage will switch to another image (to match the hovered color). And that original image will be back when the mouse leaves. Example: http://jsfiddle.net/4dK2x/27/ I also added another hover function on ProductImage for switching images between front view and back view and it's working well. (You would see the two src attributes of the .main class image in my php code as follows) However, the hover function on colors is not working when I run php code to create a dynamic list. Here are my category.php. ---- $sql = mysqli_query($db_connect, "SELECT p.id,p.style,c.color_palette, GROUP_CONCAT(DISTINCT CONCAT(c.color_palette) ORDER BY p.id SEPARATOR '+') color_palettes FROM product_details AS pd INNER JOIN products AS p ON p.id=pd.product_id INNER JOIN colors AS c ON c.id=pd.color_id INNER JOIN subcategories AS sub ON sub.id=p.subcategory_id INNER JOIN categories AS cat ON cat.id=sub.category_id WHERE category='$category' GROUP BY p.id LIMIT 6"); [...] $i= 0; $Output= '<table><tr>'; while($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){ $id = $row["id"]; $color_palette = $row["color_palette"]; $style = $row["style"]; $color_palettes = explode("+", $row["color_palettes"]); $Output.= '<td><div class="image"><a href="product.php?id='.$id .'&colorpalette='.$color_palette.'"><img class="main" data-alt-src="images/'.$style.'.'.$color_palette.'.BR.jpg" src="images/'.$style.'.'.$color_palette.'.FR.jpg" width="300" height="327"/></a><br />'; $Output.= '<div class="toggles">'; for ($ii=0;$ii<count($color_palettes);$ii++){ if (count($color_palettes) > 1) { $Output.= '<a href="product.php?id='.$id .'&colorpalette='.$color_palettes[$ii].'"><img data-src="images/'.$style.'.'.$color_palettes[$ii].'.FR.jpg" src="images/'.$style.'.'.$color_palettes[$ii].'.CP.jpg" /></a> '; } else { $Output.= '';} } // End for loop $Output.= '</div>'; $Output.='</div></td>'; $i++; if ($i%4==0){ $Output.= '</tr><tr>';} } // End while loop $Output.= '</tr></table>'; ---- I think my problem is probably because the array $color_palettes[$ii] is not defined in .main class image. So if that i the case, what do I do to fix it? Any help would be much appreciated.
  18. Here is the problem I have been having. I have tried numerous things to resolve it. Nothing seems to work. I have my login script from this book and I put it on a live domain to test it. And I can login fine with Internet explorer and Safari. But with Chrome and Firefox. It always fails to log me in on the first attempt, it takes 2 or sometimes 3 attempts. I am thinking of using the code from this book to build a website but I am completely clueless as to why it is doing this. I have triple-checked my code and it is like in the book. Could it be my SQL table that has a problem. I tested the query in phpmyadmin in the SQL form, and it always returns the user_id. When I try to login the page kind of jumps and it redirects me to index.php without logging me in. I have been at this for 3 days, any help would be HIGHLY appreciated.
  19. I built a login page from the model in this book, and for some reason, sometimes when I login it redirects me back to index.php and it doesn't log me in. Other times it logs me in just fine. Any idea what could be causing this? Here is my login page code. <?php $page_title = 'Login to your account'; include ('includes/header.html'); include ('includes/config.inc.php'); if ($_SERVER['REQUEST_METHOD'] == 'POST'){ require (MYSQL); $trimmed = array_map('trim', $_POST); if (!empty($trimmed['Email']) && filter_var($trimmed['Email'], FILTER_VALIDATE_EMAIL)){ $e = mysqli_real_escape_string($dbc, $trimmed['Email']); } else { $e = FALSE; echo '<p class="error">You forgot to enter your email address, or the email you entered is invalid.</p>'; } if (!empty($trimmed['Pass'])){ $p = mysqli_real_escape_string($dbc, $trimmed['Pass']); } else { $p = FALSE; echo '<p class="error">You forgot to enter your password, or the password you entered is invalid.</p>'; } if ($e && $p){ $q = "SELECT UserID, Fname FROM users WHERE (Email='$e' AND Pass=SHA1('$p')) AND Active IS NULL"; $r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br /> Mysql Error:" . mysqli_error($dbc)); if (@mysqli_num_rows($r) == 1){ $_SESSION = mysqli_fetch_array($r, MYSQLI_ASSOC); mysqli_free_result($r); mysqli_close($dbc); $url = BASE_URL . 'index.php'; ob_end_clean(); header("Location: $url"); exit(); } else { echo '<p class="error">Either the username and password you entered do not match those we have on file, or you have not yet activated your account.</p>'; } } else { echo '<p class="error">Please Try Again</p>'; } mysqli_close($dbc); } ?> <div class="text"> <h1>Login</h1> <p>Your browser must allow cookies in order to log in.</p> <form action="login.php" method="post"> <fieldset> <p><b>Email: <input type="text" name="Email" /></b></p> <p><b>Password: <input type="password" name="Pass" /></b></p> <input type="submit" name="submit" value="Login!" /> </fieldset> </form> </div> <? include ('includes/footer.html'); ?>
  20. In the following code I am validating a url in a practice page I am using from the stuff I learned in the book­. When I enter an invalid url in my form, I get an $url undefined error when running the code below. I am guessing the error is pretty easy to spot, but I am new at this. if (filter_var($scrubbed['url'], FILTER_VALIDATE_URL)){ $url = mysqli_real_escape_string($dbc, $scrubbed['url']); } else { echo '<p class="error">Please enter a valid url</p>'; }
  21. I am on Chapter 18, I created all the files and they seem to be all like it is written in the book, when I logout I can still see the user menu, if I click on one of the user links it takes me back to the index.php (some of the time) page which is great, meaning I am logged out. But why can I still see the Logged in User links even after I click on logout, sometimes when I click on the user links I can even get to the logged in page after I am logged out. I double checked my login and logout pages and they seem the same as in the book. Is this normal??
  22. hi i uploaded a website using the includes infrastructure exampled in this book my base uri for xamp is define ('BASE_URI', '/C:xamp/htdocs/'); and it works fine but im using filezilla to upload folders to my site hosting on go daddy and when i use my httpdocs path define ('BASE_URI', '/httpdocs/'); i get this error: PHP Fatal error: require(): Failed opening required '/httpdocs/mysql.inc.test.php' (include_path='.;.\includes;.\pear') in G:\PleskVhosts\axebs.com\httpdocs\index.php on line 16 any tips on what i need to set my path to to work on filezilla??
  23. i have to tables that are link and i want to view contents of a single item when i select it, what is the correct syntax of using $post in yii ie SELECT tbl_emp.emp_id, tbl_emp.sname, tbl_fname, tbl_educ.empl_id FROM tbl_emp, tbl_edu WHERE tbl_emp.emp_id=$_POST['emp_id'] AND tbl_edc.emp_id=$_PSOT['emp_id'];
  24. In Chapter 19, the $_SESSION['customer_id'] variable is often used for things like isset($_SESSION['customer_id']) why though can't we use other table columns that are like customer_id in the $_SESSION[] for example $_SESSION['order_id'] In chapter 19 also, the $_GET['id'] is the same id as the customer's. Why is it the same? Where does it get declared as the same, I have searched through the scripts and I don't see it. I am trying to create a script where users can view their past orders. The trouble I am having is calculating the total amount of the order in the checkout.php script, because there is no customer_id field in the order_contents table. Here is where I am at with that in the checkout.php script: $u = "SELECT price * quantity AS amount FROM order_contents WHERE order_id=?not sure what to put here"; $total = mysqli_query($dbc, $u);
  25. In page 99, session_regenerate_id() cause en error "Cannot regenerate session id - headers already sent". If i comment this function out, everything goes fine. Where I should check for problem? thanks
  • Create New...