Jump to content

GypsyBoy

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by GypsyBoy

  1. I’m new to php and MySQL, and i'm just getting my feet dirty... Basically i am working on a message board, i need to be able to post a thread like you would do normally and also ask for post code, to be stored with the thread. Then I want to modify search.php and create a field where you type post code of your liking and have it compared WITH thread post code and then calculate the distance between post code in a thread and post code you type into search Does that make sense? How do I go about that?. Here’s a good one: http://www.geopostcode.org.uk/findmynearest.php Any thing else? Oh and I need a UK version of this (for now) as you probably guessed!
  2. Ahhhhhhhhhhhhhhhh it works!!!! Good **** !!! Thanks so much for helping me out
  3. Its important that i figure this out before moving to next chapters
  4. <?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 user name: if (empty($_POST['user_name'])) { $errors[] = 'You forgot to enter your user name.'; } else { $ln = mysqli_real_escape_string($dbc, trim($_POST['user_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 user_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 user_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>User Name: <input type="text" name="user_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'); ?>
  5. I been working on this script i got from a PHP MySQL book... And im stuck on a simple script chapter 10. I posted on book authors website but he didnt reply yet... This: https://ibb.co/kyYQFS Is the error. Please someone help me debug this freaking program.
×
×
  • Create New...