Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'help'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • 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

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 4 results

  1. I have been getting some errors in my chapter 13 site and I am not sure how I can fix them. I am able to login with the login.php page. When I do I get this error. ?php // Script 13.4 - footer.html // Display general admin links... // - if the user is an administrator and it's not the logout.php page // - or if the $loggedin variable is true (i.e., the user just logged in) if ( (is_administrator() && (basename($_SERVER['PHP_SELF']) != 'logout.php')) OR (isset($loggedin) && $loggedin) ) { // Create the links: print ' When I go to the add_quotes.php page I get this error. When I try and add a quote I get this list of errors. Here is my add_quotes.php code I am getting a red underline error on the ! is administrator line I added LINE is # where each line error is for my error list above <?php // Script 13.7 - add_quote.php /* This script adds a quote. */ // Define a page title and include the header: define('TITLE', 'Add a Quote'); include('templates/header.html'); print '<h2>Add a Quotation</h2>'; // Restrict access to administrators only: if (!is_administrator()) { (THIS LINE IS GIVING ME AN ERROR) print '<h2>Access Denied!</h2><p class="error">You do not have permission to access this page.</p>'; include('templates/footer.html'); exit(); } // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form. if ( !empty($_POST['quote']) && !empty($_POST['source']) ) { // Need the database connection: LINE 23 include('C:/xampp/htdocs/PHP/Chapter13/mysqli_connect.php'); // Prepare the values for storing: LINE 26 $quote = mysqli_real_escape_string($dbc, trim(strip_tags($_POST['quote']))); LINE 27 $source = mysqli_real_escape_string($dbc, trim(strip_tags($_POST['source']))); // Create the "favorite" value: if (isset($_POST['favorite'])) { $favorite = 1; } else { $favorite = 0; } $query = "INSERT INTO quotes (quote, source, favorite) VALUES ('$quote', '$source', $favorite)"; LINE 37 mysqli_query($dbc, $query); LINE 39 if (mysqli_affected_rows($dbc) == 1){ // Print a message: print '<p>Your quotation has been stored.</p>'; } else { print '<p class="error">Could not store the quote because:<br>' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>'; } // Close the connection: LINE 47 mysqli_close($dbc); } else { // Failed to enter a quotation. LINE 43 print '<p class="error">Please enter a quotation and a source!</p>'; } } // End of submitted IF. // Leave PHP and display the form: ?> <form action="add_quote.php" method="post"> <p><label>Quote <textarea name="quote" rows="5" cols="30"></textarea></label></p> <p><label>Source <input type="text" name="source"></label></p> <p><label>Is this a favorite? <input type="checkbox" name="favorite" value="yes"></label></p> <p><input type="submit" name="submit" value="Add This Quote!"></p> </form> <?php include('templates/footer.html'); ?>
  2. Hi, I recently posted a question here but have not heard anything back. Is anyone still moderating this forum? (if you click my name you'll find my post). Just bought this book and could use help from time to time. Thanks, Chris
  3. Hello. I want to do the exercises at the end of chapter 10 but I need help. If any one can help that would be greatly appreciated. Here is the code and I have commented in what needs to happen according to the book's exercises: Change the delete and edit user pages so that they display the user being affected in the title bar of your browser window.<?php # Script 10.2 - delete_user.php // This page is for deleting a user record. // This page is accessed through view_users.php. $page_title = 'Delete a User'; include ('includes/header.html'); echo '<h1>Delete a User</h1>'; // Check for a valid user ID, through GET or POST: if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // From view_users.php $id = $_GET['id']; } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form submission. $id = $_POST['id']; } else { // No valid ID, kill the script. echo '<p class="error">This page has been accessed in error.</p>'; include ('includes/footer.html'); exit(); } require ('../mysqli_connect.php'); // Check if the form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_POST['sure'] == 'Yes') { // Delete the record. // Make the query: $q = "DELETE FROM users WHERE user_id=$id LIMIT 1"; $r = @mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Print a message: echo '<p>The user has been deleted.</p>'; } else { // If the query did not run OK. echo '<p class="error">The user could not be deleted due to a system error.</p>'; // Public message. echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message. } } else { // No confirmation of deletion. echo '<p>The user has NOT been deleted.</p>'; } } else { // Show the form. // Retrieve the user's information: $q = "SELECT CONCAT(last_name, ', ', first_name) FROM users WHERE user_id=$id"; $r = @mysqli_query ($dbc, $q); if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form. // Get the user's information: $row = mysqli_fetch_array ($r, MYSQLI_NUM); // Display the record being deleted: echo "<h3>Name: $row[0]</h3> Are you sure you want to delete this user?"; // Create the form: echo '<form action="delete_user.php" method="post"> <input type="radio" name="sure" value="Yes" /> Yes <input type="radio" name="sure" value="No" checked="checked" /> No <input type="submit" name="submit" value="Submit" /> <input type="hidden" name="id" value="' . $id . '" /> </form>'; } else { // Not a valid user ID. echo '<p class="error">This page has been accessed in error.</p>'; } } // End of the main submission conditional. mysqli_close($dbc); include ('includes/footer.html'); /*This is what needs to happen: Change the delete and edit user pages so that they display the user being affected in the title bar of your browser window. Modify edit_user.php so that you can also change a user's password (remember to SHA the password for storage in the database). */ ?> <?php # Script 10.3 - edit_user.php // This page is for editing a user record. // This page is accessed through view_users.php. $page_title = 'Edit a User'; include ('includes/header.html'); echo '<h1>Edit a User</h1>'; // Check for a valid user ID, through GET or POST: if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // From view_users.php $id = $_GET['id']; } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form submission. $id = $_POST['id']; } else { // No valid ID, kill the script. echo '<p class="error">This page has been accessed in error.</p>'; include ('includes/footer.html'); exit(); } require ('../mysqli_connect.php'); // Check if the form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = 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 a 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'])); } if (empty($errors)) { // If everything's OK. // Test for unique email address: $q = "SELECT user_id FROM users WHERE email='$e' AND user_id != $id"; $r = @mysqli_query($dbc, $q); if (mysqli_num_rows($r) == 0) { // Make the query: $q = "UPDATE users SET first_name='$fn', last_name='$ln', email='$e' WHERE user_id=$id LIMIT 1"; $r = @mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Print a message: echo '<p>The user has been edited.</p>'; } else { // If it did not run OK. 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 { // Already registered. echo '<p class="error">The email address has already been registered.</p>'; } } else { // Report the errors. echo '<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>'; } // End of if (empty($errors)) IF. } // End of submit conditional. // Always show the form... // Retrieve the user's information: $q = "SELECT first_name, last_name, email FROM users WHERE user_id=$id"; $r = @mysqli_query ($dbc, $q); if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form. // Get the user's information: $row = mysqli_fetch_array ($r, MYSQLI_NUM); // Create the form: echo '<form action="edit_user.php" method="post"> <p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="' . $row[0] . '" /></p> <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="' . $row[1] . '" /></p> <p>Email Address: <input type="text" name="email" size="20" maxlength="60" value="' . $row[2] . '" /> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="id" value="' . $id . '" /> </form>'; } else { // Not a valid user ID. echo '<p class="error">This page has been accessed in error.</p>'; } mysqli_close($dbc); include ('includes/footer.html'); /*This is what needs to happen: Change the delete and edit user pages so that they display the user being affected in the title bar of your browser window. Modify edit_user.php so that you can also change a user's password (remember to SHA the password for storage in the database). */ ?>
  4. I want to use the Query Builder as described in the yii manual: http://yiiframework.ru/doc/guide/en/database.query-builder I struggle with the documentation as it does not specify exactly where to put things. I have an SQL query that I know works on my MySQL database. I have tried formatting it according to the directions at the link I pasted above. My problem is that I don't understand where to put it. I am testing it on a table called people. The model is call People too. Here is the query as I understand, translated in yii: $user = Yii::app()->db->createCommand() ->select('Sum(IFNULL(yr1,0)) + IFNULL(yr2,0) + IFNULL(yr3,0) + IFNULL(yr4,0) + IFNULL(yr5,0) + IFNULL(yr6,0) + IFNULL(yr7,0) + IFNULL(yr8,0) + IFNULL(yr9,0) + IFNULL(yr10,0) AS Total ') ->from('people') ->group by('id');
×
×
  • Create New...