Code Check Please

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Have you done a view source on the blank page to see if there is nothing there or if you header might be getting written wrong.

And is the email part still not working. Meaning it is still not sending an email?
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

mrvanjohnson

Post by AliasBDI »

The source for the page is blank. It only has the minimal HTML tags for an empty page. AND yes, email is still not working.
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Echo out your Select Statement and Echo out the results so that you can see it is pulling something from the database. Once you have confirmed that let us know. Still not sure why it's not redirecting but lets break down the problem piece by piece. First confirm you are request data from the database and that you are getting that data back. Next, echo out the Email message so you know the email is being formed correctly. Then we can stop worrying if it's anything before the mail function.
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

mrvanjohnson

Post by AliasBDI »

I added some short echo code after the query. I receive the same result that I did before. Also, I queried this against the database in MyPHPAdmin and had a positive result.

Code: Select all

$result = mysql_query("SELECT first_name, last_name, email_address, username, decrypted_password, dl, birth FROM users WHERE dl='$dl' AND birth='$birth' ") or die (mysql_error());
if (!$result) {
    print "ERROR - browse query failed.";
    exit();
}
while ( $row = mysql_fetch_array($result) )
{

$username = $rowї'username'];
echo "Test: ";
echo $username;
exit();
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

If you are still getting a blank page after adding those echos then the code isn't even making it to that section. Did you try to add the Error reporting JAM recommended a few postings back?

Let's see where this is breaking... try this

Code: Select all

<?php
include '../includes/db.php'; 
echo "File has been included <br /> \n";

// Define post fields into simple variables.  These are called CONSTANTS. 
$dl = $_POST['dl']; 
$birth = $_POST['birth']; 

echo "\$dl is set to $dl <br /> \n";
echo "\$birth is set to $birth <br /> \n";

/* Lets strip some slashes in case the user entered 
any escaped characters. */ 
$dl = stripslashes($dl); 
$birth = stripslashes($birth); 

echo "Now \$dl is set to $dl <br /> \n";
echo "Now \$birth is set to $birth <br /> \n";

/* Do some error checking on the form posted fields */ 

if((!$dl) || (!$birth)){ 
echo "In first loop <br /> \n";
header('Location: forgot2.php'); 
   /*echo 'You did not submit the following required information! <br />'; 
   if(!$dl){ 
      echo "Drivers License is a required field. Please enter it below.<br />"; 
   } 
   if(!$birth){ 
      echo "Birth Date is a required field. Please enter it below.<br />"; 
   } 

   include 'forgot.php'; // Show the form again! 
   /* End the error checking and if everything is ok, we'll move on to 
    creating the user account */ 
   exit(); // if the error checking has failed, we'll exit the script! */ 
} 
?>
I actually went throught the trouble of testing this code and everything works. The only two things I couldn't account for was the include statement which I just commented out and (a question I should have asked earlier I know) I could not confirm that your form is actually using a POST method and not a GET method. Besides those two things, you should most definiently see some output after adding these other echos. Even if the file is not being included correctly, you don't have it required so the rest of the code should still fire off. Let us know how it goes.
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

mrvanjohnson

Post by AliasBDI »

I did not try the Error reporting as JAM recommeded because I do not have access to the file which determines the level of errors.

I copy/pasted and tested your code. I have my $dl record as "2222" and my $birth record as "3333" (so that I don't publicize my real information). So I typed those two in the form and executed it. Now the page in discussion returns the echos like this:
File has been included
$dl is set to 2222
$birth is set to 3333
Now $dl is set to 2222
Now $birth is set to 3333
So this part of the code seems to be working okay.

The form is set to POST as you well know now.

What next?
Chambrln
Forum Commoner
Posts: 43
Joined: Tue Dec 02, 2003 10:45 am
Location: Oregon

Post by Chambrln »

You're missing a close bracket at the end of your while loop.

Code: Select all

<?php
while ( $row = mysql_fetch_array($result) ) 
{ 

$username = $row['username']; 
echo "Test: "; 
echo $username; 
?>
Whould be:

Code: Select all

<?php
while ( $row = mysql_fetch_array($result) ) 
{ 
$username = $row['username']; 
echo "Test: "; 
echo $username; 
}
?>
Usually when you don't get anything outputting to a page it's because you have forgotten a closing parenthesis or a closing bracket. At least that has been my experience.
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Chambrln he does have a closing } if you look at the end of the code he posted it's there above the closing ?>


AliasBDI, JAM shows you how to add the error reporting to your page without needing to edit the PHP.ini file
Checking it: PHP:
echo 'Error Level: '.(ini_get('error_reporting') == '2047' ? 'E_ALL' : 'Not E_ALL')."\n";

If it's not E_ALL;
Setting it: PHP:

ini_set ('error_reporting', E_ALL);

(added on top of the page)
I am running out of ideas myself. The last thing I noticed is that you are referencing some variables in setting the $message that have not been defined (for example $sitepath and $sitename under $subject).. I assume that these variables are set by the include.

Other than that the only thing I see suspect is your mail function. Drop the From into a variable and change your mail setting. You might want to try echoing out the email to see if it's all be configured correctly. Also, have you used the mail function on this box before. You know that it works?

I'm afraid I am out of ideas after that.
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

mrvanjohnson

Post by AliasBDI »

I added the error level code you described. Now the page shows this when called:

Code: Select all

Error Level: Not E_ALL
Also the variables ARE stated in the include file.
Post Reply