Jump to content

infophiliac

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

infophiliac's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I haven't actually managed to wrap my head around all the why and wherefore, but I did solve the problem.  The average needed to be assigned an alias, so "SELECT AVG(rating)..." became "SELECT AVG(rating) as r."  Like I said, I'm still figuring out why that is so, but the immediate issue is resolved.
  2. I'm trying to send the following query from a page written with PHP: $query = "SELECT AVG(rating) FROM ratings WHERE rtime >= SUBDATE(NOW(), INTERVAL 2 HOUR) AND id=1"; When I run the query from the MySQL command line, it comes back with exactly what it should.  When I run the page with that query, it returns nothing (including no error message).  I've debugged to the point where I know that the query works if I take out AVG(), but can't for the life of me see why. I'm running MySQL 4.0 and PHP 4.4.1 on FreeBSD. Any insights would be appreciated.
  3. [!--quoteo(post=373010:date=May 10 2006, 01:57 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 10 2006, 01:57 PM) [snapback]373010[/snapback][/div][div class=\'quotemain\'][!--quotec--] Try removing the processing code and just loading the form to see if that works. [/quote] The page still loads, but it still goes directly to the "Thanks, you're registered" state.
  4. [!--quoteo(post=373002:date=May 10 2006, 01:49 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 10 2006, 01:49 PM) [snapback]373002[/snapback][/div][div class=\'quotemain\'][!--quotec--] Well, I'm not sure why you put your form up above the processing code, because if you hit errors, wouldn't you want the form to show again with the errors showing? Other than that, I'm not sure what's going on. If you look at the source, is the code for the form there? If it is, I'd say you have a layout issue, not a PHP issue. [/quote] Oops. That was initially at the end, but I tried moving it to the beginning when the form wasn't recognized to see if it would make any difference and forgot to move it back to the end. Incidentally, it didn't make a difference (although I'm sure that's more because whatever the basic issue is was preventing things from getting to the point where the location of the form mattered).
  5. I'm in the midst of trying to create a registration form and everything appears to be running beautifully on the registration page except for the little matter of the form not being displayed. When the page is loaded, it immediately goes to "Thanks, you're registered" without ever collecting the data to be submitted to MySQL. Here's the code and any insights would be appreciated. [code] <?php # Scrip 7.3 - register.php $page_title = 'Register'; include ('./includes/header.html'); ?> <h2>Register</h2> <form action="register.php" method="post">     <p>First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>     <p>Last Name: <input type="text" name="last_name" size="15" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>     <p>Email Address: <input type="text" name="email" size="20" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Password: <input type="password" name="password1" size="10" maxlength="20" /></p> <p>Password: <input type="password" name="password2" size="10" maxlength="20" /></p> <p><input type="submit" name="submitted" value="TRUE" /> </form> <?php // Check if the form has been submitted. if (isset($_POST['submitted'])) {     $errors = array(); // Initialize error array.     // Check for a first name.     if (empty($_POST['first_name'])) {         $errors[] = 'You forgot to enter your first name.';     } else {         $fn = trim($_POST['first_name']); }     // Check for a last name.     if (empty($_POST['last_name'])) {         $errors[] = 'You forgot to enter your last name.';     } else {         $ln = trim($_POST['last_name']); }     // Check for a email address.     if (empty($_POST['email'])) {         $errors[] = 'You forgot to enter your email address.';     } else {         $e = trim($_POST['email']); }     // Check for a password and match against the confirmed password.     if (!empty($_POST['password1'])) {         if ($_POST['password1'] != $_POST['password2']) {             $errors[] = 'Your password did not match the confirmed password.';         } else {             $p = trim($_POST['password1']);         }     } else {         $errors[] = 'You forgot to enter your password.';     }      }     if (empty($errors)) { // If everything's okay.         //Register the user in the database.         require_once ('../mysql_connect.php'); // Connect to the db.         // Make the query.         $query = "INSERT INTO users (first_name, last_name, email, password, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )";         $result = @mysql_query ($query);         if ($result) { // If it ran OK.             // Send an email, if desired.         // Print a message.         echo '<h1 id="mainhead">Thank you!</h1>     <p>You are now registered.</p><p><br /></p>';         // Include the footer and quite the script (to not show the form).         include ('./includes/footer.html');         exit();     } else { // If it did not run OK.         echo '<h1 id="mainhead">System Error!</h1>         <p class="error">You could not be registered due to a system error.  We apologize for any inconvenience.</p>'; // Public message.         echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p> '; // Debugging message.         include ('./includes/footer.html');         exit(); }         mysql_close(); // Close the database connection.     } else { // Report the errors.         echo '<h1 id="mainhead">Error!</h1>         <p class="error">The following error(s) occurred:<br />';         foreach ($errors as $msg) { // Print each error.             echo " - $msg<br />\n";     } // End of if (empty($errors)) IF. } //  End of the main Submit conditional. include ('./includes/footer.html'); ?> [/code]
  6. [!--quoteo(post=369670:date=Apr 28 2006, 03:25 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 28 2006, 03:25 PM) [snapback]369670[/snapback][/div][div class=\'quotemain\'][!--quotec--] Just as I though, You have a missing [b]'[/b] on this line: [code] echo '<p><font color="red">You forgot to enter your name!</font></p>;[/code] Notice there is no ' before the ; in the above code. To solve this just put a ' before the ; so you line is like this: [/quote] ...and this is why I'm posting on the newbie board. Thanks man!
  7. [!--quoteo(post=369666:date=Apr 28 2006, 03:11 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 28 2006, 03:11 PM) [snapback]369666[/snapback][/div][div class=\'quotemain\'][!--quotec--] Looking at your code it is fine. However I think the error is comming from above line 28. [/quote] Bugger. OK, here's all the body leading up to what I previously posted. [code] <body> <?php # Script 2.9 - handle_about.php if (!empty($_POST['name'])) {     $name = stripslashes($_POST['name']); } else {     $name = NULL;     echo '<p><font color="red">You forgot to enter your name!</font></p>; } if (isset($_POST['interests'])) {     $interests = TRUE; } else {     $interests = NULL;     echo '<p><font color="red">You forgot to enter your interests!</font></p>; } [/code] Everything still look OK? This has occured on every page on which I've tried to use the isset conditional and it's threatening to drive me buggy.
  8. I've been running into the same problem on a number of different pages that I've copied out of the book from which I'm learning PHP. The site for the book doesn't list any corrections to this code, so I assume it's a problem that I'm having and not an error in the book. I'm using PHP v. 4.4.1 on the FreeBSD OS. I'm hosted by Startlogic.com. An example of one that has given me trouble is: [code] if (isset($_POST['interests'])) {     $interests = TRUE; } else {     $interests = NULL;     echo '<p><font color="red">You forgot to enter your interests!</font></p>; } [/code] The error message: Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/wordofno/public_html/learningphp/handle_about.php on line 28 Line 28 yere is the first line of quoted code, but nowhere in that line (or any of the subsequent lines) is a semi-colon or comma called for and not used. Any insights would be appreciated.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.