Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'edit'.



More search options

  • 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 5 results

  1. <?php // This page is for editing a user record. // This page is accessed through view_users.php. // Require the configuration before any PHP code as the configuration controls error reporting: require('./includes/config.inc.php'); // Require the database connection: require(MYSQL); // Include the header file: $page_title = 'Edit User'; include('./includes/header.html'); // 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 '<div class="alert alert-warning"><h3 class="text-center">This page has been accessed in error.</h3></div>'; include ('includes/footer.html'); exit(); } // For storing errors: $edit_user_errors = array(); // Check if the form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Check for a first name: if (preg_match('/^[A-Z \'.-]{2,45}$/i', $_POST['first_name'])) { $fn = escape_data($_POST['first_name'], $dbc); } else { $edit_user_errors['first_name'] = 'Please enter your first name.'; } // Check for a last name: if (preg_match('/^[A-Z \'.-]{2,45}$/i', $_POST['last_name'])) { $ln = escape_data($_POST['last_name'], $dbc); } else { $edit_user_errors['last_name'] = 'Please enter your last name.'; } // Check for a country: if (filter_var($_POST['country'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $c = $_POST['country']; } else { // No country selected. $edit_user_errors['country'] = 'Please select your country.'; } // Check for an email address: if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === $_POST['email']) { $e = escape_data($_POST['email'], $dbc); } else { $edit_user_errors['email'] = 'Please enter a valid email address.'; } if (empty($edit_user_errors)) { // If everything's OK. // Test for unique email address: $q = "SELECT id FROM users WHERE email='$e' AND id != $id"; $r = @mysqli_query($dbc, $q); if (mysqli_num_rows($r) == 0) { // Make the query: $q = "UPDATE users SET last_name='$ln', first_name='$fn', country='$c', email='$e' WHERE id=$id LIMIT 1"; $r = @mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Print a message: echo '<div class="alert alert-success"><h3 class="text-center">The user has been edited.</h3></div>'; } else { // If it did not run OK. trigger_error('<div class="alert alert-warning"><h3>You could not be registered due to a system error. We apologize for any inconvenience. We will correct the error ASAP.</h3></div>'); } } else { // Already registered. $edit_user_errors['email'] = 'The email address has already been registered.'; } } } // End of submit conditional. // Always show the form: // Retrieve the user's information: $q = "SELECT u.last_name, u.first_name, c.country, u.email FROM users AS u INNER JOIN countries AS c USING (country_id) WHERE 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); require_once('./includes/form_functions.inc.php'); // Create the form: ?> <h3>Edit User</h3> <p>Use this page to edit a user.</p> <form action="edit_user.php" method="post" accept-charset="utf-8"> <?php create_form_input('last_name', 'text', '', $edit_user_errors, array('placeholder'=>'Last Name')); create_form_input('first_name', 'text', '', $edit_user_errors, array('placeholder'=>'First Name')); // Add the country drop down menu: echo '<div class="form-group'; if (array_key_exists('country', $edit_user_errors)) echo ' has-error'; echo '"><select name="country" class="form-control"> <option>Select Country</option>'; // Retrieve all the country and add to the pull-down menu: $q = "SELECT country_id, country FROM countries ORDER BY country ASC"; $r = mysqli_query($dbc, $q); while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['country']) && ($_POST['country'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } echo '</select>'; if (array_key_exists('country', $edit_user_errors)) echo '<span class="help-block">' . $edit_user_errors['country'] . '</span>'; echo '</div>'; create_form_input('email', 'email', '', $edit_user_errors, array('placeholder'=>'Email Address')); ?> <input type="submit" name="submit_button" value="Update User" id="submit_button" class="btn btn-primary" /> <input type="hidden" name="id" value="' . $id . '" /> </form> <br> <?php } else { // Not a valid user ID. echo '<div class="alert alert-warning"><h3 class="text-center">This page has been accessed in error.</h3></div>'; } mysqli_close($dbc); include ('includes/footer.html'); ?> I am busy adding an admin function (to edit registered users) to the first web application - "selling virtual goods". I have the following questions: How do I get the above form to display the stored values for a selected user? I am using the original form_functions.inc.php script. How do I get the select option (Country) to recall the stored value for the user? I am using Apache 2.4.12, PHP 5.6.8 and MySQL5.0.11. Any help will be much appreciated.
  2. I'm not sure if this is even possible but I would like to modify script 10.3. I have created a simple running log where users can input the details of their run using a form that includes text input, radio buttons and drop-down menus. Is it possible to use the same or similar form to edit/update their records? I have no problem retrieving the values for the text boxes but I don't know how the form is supposed to show the values from the drop down menus or to "select" the appropriate radio button. Any help would be appreciated. Thanks!
  3. I used script 10.5 as a model for view_households.php but get he following error message: ------------ warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/00/10035700/html/pumc/edit_household.php on line 97 This page has been accessed in error without valid hh_id -------------------- <?php # Script 10.5 - #5 // This script retrieves all the records from the users table. // This new version allows the results to be sorted in different ways. session_start();// access session variables. $page_title = 'View the Current Households'; include ('includes/header.html'); echo '<h1>Registered Users</h1>'; require ('includes/mysqli_connect.php'); // Number of records to show per page: $display = 10; // Determine how many pages there are... if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined. $pages = $_GET['p']; } else { // Need to determine. // Count the number of records: $q = "SELECT COUNT(hh_id) FROM Households"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; // Calculate the number of pages... if ($records > $display) { // More than 1 page. $pages = ceil ($records/$display); } else { $pages = 1; } } // End of p IF. // Determine where in the database to start returning results... if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Determine the sort... // Default is by last name. $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'ln'; // Determine the sorting order: switch ($sort) { case 'ln': $order_by = 'LastName ASC'; break; case 'fn': $order_by = 'FirstName ASC'; break; default: $order_by = 'LastName ASC'; $sort = 'ln'; break; } // Define the query: $q = "SELECT LastName, FirstName, hh_id FROM Households ORDER BY $order_by LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); // Run the query. // Table header: echo '<table align="center" cellspacing="0" cellpadding="5" width="75%"> <tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b><a href="view_users.php?sort=ln">Last Name</a></b></td> <td align="left"><b><a href="view_users.php?sort=fn">First Name</a></b></td> //<td align="left"><b><a href="view_users.php?sort=rd">Date Registered</a></b></td> </tr> '; // Fetch and print all the records.... $bg = '#eeeeee'; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); echo '<tr bgcolor="' . $bg . '"> <td align="left"><a href="edit_household.php?id=' . $row['hh_id'] . '">Edit</a></td> <td align="left"><a href="delete_household.php?id=' . $row['hh_id'] . '">Delete</a></td> <td align="left">' . $row['LastName'] . '</td> <td align="left">' . $row['FirstName'] . '</td> //<td align="left">' . $row['dr'] . '</td> </tr> '; } // End of WHILE loop. echo '</table>'; mysqli_free_result ($r); mysqli_close($dbc); // Make the links to other pages, if necessary. if ($pages > 1) { echo '<br /><p>'; $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button: if ($current_page != 1) { echo '<a href="view_Households.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> '; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="view_Households.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> '; } else { echo $i . ' '; } } // End of FOR loop. // If it's not the last page, make a Next button: if ($current_page != $pages) { echo '<a href="view_households.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>'; } echo '</p>'; // Close the paragraph. } // End of links section. include ('includes/footer.html'); ?> ----------------------- When I run "view_households.php" I see the table of records. When I click the EDIT link it displays "edit_households.php" with ....php?id.... But then I get the error that no valid hh_id is available. I would appreciate any help. I have been struggling with this for days. Thanks in advance. Wes Smith
  4. is it possilbe to update two tables using the same code from Chapter 12 "Updating Data in a Databse"? if it is possible, can you teach me how to do it? for example.. TABLE 1 recordid.. name...basicinfo TABLE 2 recordid...login... password
  5. Page 108, version 0.5 The following sentence seems to jump over several points, each of which needs a more detailed explanation. Consequently, I cannot understand this sentence at all: "the form used to both create and edit a record is its own file, and that file can be included by both create.php and update.php (those two files start by changing the headings above the form)." Larry, can you break this down please? Thanks.
×
×
  • Create New...