Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Having problems emailing query results

Codes here !

Moderators: macek, egami, gesf

Having problems emailing query results

Postby dmyers » Tue Jun 24, 2003 12:34 pm

Ok, I am fairly new to php, but have been doing Visual Basic and C++ for years so I have the theories and pricipals of programming down pretty good.

I am having two problems with this page that are driving me NUTS. I have looked and looked, tried and tried but can not seem to find the problem.

The php page is a lost password utility for a website I am designing. The first problem is that when the page first appears, it displays every record in the database. This is done because I have used echo to display the results of my query, but even if I didn't echo the results it would still be pulling every record to begin with. I need it to not make any query until the "Submit" button is clicked.

The second problem is that it will not mail the password to the user, who's email address is the vaiable $uemail. That vaiable is retrived from a text box on the form that is filled in by the user. The form then should query the database looking for anyone with that email address and email the required information back to the user at that email address.


Can someone help me and tell me what I am doing wrong? :?:


Code: Select all
<html>
<head>
<title>Find Password</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style>
td{
font-family:arial;
font-size:8pt;
color:#696969;
}
.wh{
color:white;
}
.more{
color:#0974A6;
}
.menu{
color:#748B3D;

}
</style>

</head>

<body bgcolor="#FFFFFF">
<table width="60%" border="0" cellspacing="5" cellpadding="0" align="center">
<tr>
<td colspan="3">
<div align="center"></div>
</td>
</tr>
<tr>
<td width="17%">
<div align="left"><img src="../../images/GLTA-logo-new.gif" width="120" height="98"></div>
</td>
<td width="62%">
<div align="center"><b><font color="#000000">Please note that if you have
not set up your Password Retrieval Profile, which includes providing your
e-mail address, you will not be able to use this feature.</font></b></div>
</td>
<td width="21%"><img src="../../images/GLTA-logo-new.gif" width="120" height="98"></td>
</tr>
<tr>
<td colspan="3" height="11">&</td>
</tr>
</table>
<form name="form1" >
<table width="342" border="1" cellspacing="3" cellpadding="3" bordercolor="#333333" align="center">
<tr align="center" bgcolor="A5E2FF">
<td colspan="2"><font face="Tahoma"><b><font color="#FF0000">Retrieve Account
Information</font></b></font></td>
</tr>
<tr bgcolor="#CCCCCC">
<td width="224" bgcolor="#FFFFCC">
<input type="text" name="uemail" size="30" value="Type your email address here">
</td>

<td width="118" bgcolor="#FFFFCC">
<input type="submit" name="Submit" value="Find Account">
</td>
</tr>
</table>
</form>
<table width="40%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<div align="center"><b><font color="#000000">Click <a href="../login.php" target="_self">here</a>
to go back to the login screen.</font></b> </div>
</td>
</tr>
</table>


<?
@mysql_connect('*****', '*****', '*****') or die(mysql_error());
@$result = mysql_list_tables('*****') or die(mysql_error());

$sql = "SELECT * FROM authuser WHERE email = '$uemail'";
@$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');

while ($row = mysql_fetch_row($result)) {
// $tb_names[] = $row[0];
// echo "System ID: ";
// echo $row[0].'<br />';
echo "First Name: ";
echo $row[8].'<br />';
echo "Last Name: ";
echo $row[9].'<br />';
echo "User Group: ";
echo $row[3].'<br />';
echo "Status: ";
echo $row[5].'<br />';
echo "Username: ";
echo $row[1].'<br />';
echo "Password: ";
echo $row[11].'<br />';
// echo "Encrypted Password: ";
// echo $row[2].'<br />';
// echo "Level: ";
// echo $row[4].'<br />';
// echo "Last Logon: ";
// echo $row[6].'<br />';
// echo "Logon Count: ";
// echo $row[7].'<br />';
echo "E-Mail Address: ";
echo $row[10].'<br />';


$username = $row[1];
$firstname = $row[8];
$lastname = $row[9];
$password = $row[11];
$email = $row[10];
$group = $row[3];
$status = $row[5];
$uemail = $row[10];
}

$msubject = "Account information from GLTA";
$mbody .= "The account information you requested is displayed below.\n";
$mbody .= "\n";
$mbody .= "Username\t\t: $username \r\n";
$mbody .= "Password\t\t: $password \r\n";
$mbody .= "E-Mail\t\t: $email \r\n";
$mbody .= "User Group\t\t: $group \r\n";
$mbody .= "Access Level\t\t: $level \r\n";
$mbody .= "Status\t\t: $status \r\n";
$mheader = "From: GLTA Security";

$to = "$uemail <$uemail>";
$headers = "From: \"".addslashes($uemail)."\" <".$uemail.">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-Mailer: PHP / ".phpversion()."\r\n";
mail( $to, $msubject, $mbody, $headers ) or print "Error handling message. message not sent.";
?>
The email to <?=$to?> (<?=$to?> ) Was send successfully.<br><br>
The message was: <?=$mbody?><br><br>

And the headers were: <?=$headers?>
</body>
</html>
dmyers
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Jun 24, 2003 11:55 am

Postby Joan Garnet » Wed Jun 25, 2003 7:18 am

It's a big piece of code... better try to specify next time ;)

As I see, firt of all you are not sending anything even if you push the submit button:
Code: Select all
<form name="form1">

It's missing "method" to choose between POST and GET and "action" to specify where yu want it to be sent (in this case you can use action="<?php $_SERVER["PHP_SELF"] ?>" )

Then, if you want to filter the php code until the submit has been done, you will need to add a conditional.
Something like:
( I guess you will use the POST method for the form to be sent )
Code: Select all
 if ( isset ( $_POST ["uemail"] ) ){
........ php code ......
}


I think that will be it (if the rest of the code is right)
Bye!
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Error message about SQL syntax

Postby dmyers » Wed Jun 25, 2003 10:28 am

I am getting this error message.

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '@4-webdesign.net' at line 1
SELECT * FROM authuser WHERE email = dmyers@4-webdesign.net


I can not find anything wrong with the syntax.

Here is the new code.

Code: Select all

<?
if ( isset ( $_POST ["uemail"] ) ) {
@mysql_connect('localhost', 'gltanet_gltaadmi', 'gltaglta') or die(mysql_error());
@$result = mysql_list_tables('gltanet_gltauser') or die(mysql_error());

$sql = "SELECT * FROM authuser WHERE email = {$_POST['uemail']}";
@$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');

while ($row = mysql_fetch_row($result)) {
    // $tb_names[] = $row[0];
    // echo "System ID: ";
   // echo $row[0].'<br />';
   echo "First Name: ";
   echo $row[8].'<br />';
   echo "Last Name: ";
   echo $row[9].'<br />';
   echo "User Group: ";
   echo $row[3].'<br />';
   echo "Status: ";
   echo $row[5].'<br />';
   echo "Username: ";
   echo $row[1].'<br />';
   echo "Password: ";
   echo $row[11].'<br />';
   // echo "Encrypted Password: ";
   // echo $row[2].'<br />';
   // echo "Level: ";
   // echo $row[4].'<br />';
   // echo "Last Logon: ";
   // echo $row[6].'<br />';
   // echo "Logon Count: ";
   // echo $row[7].'<br />';
   echo "E-Mail Address: ";
   echo $row[10].'<br />';

      
   $username = $row[1];
   $firstname = $row[8];
   $lastname = $row[9];
   $password = $row[11];
   $email = $row[10];
   $group = $row[3];
   $status = $row[5];
   $uemail = $row[10];
}

$msubject = "Account information from GLTA";
$mbody .= "The account information you requested is displayed below.\n";
$mbody .= "\n";
$mbody .= "Username\t\t: $username \r\n";
$mbody .= "Password\t\t: $password \r\n";
$mbody .= "E-Mail\t\t: $email \r\n";
$mbody .= "User Group\t\t: $group \r\n";
$mbody .= "Access Level\t\t: $level \r\n";
$mbody .= "Status\t\t: $status \r\n";
$mheader = "From: GLTA Security";

$to  = "$uemail <$uemail>";
$headers = "From: \"".addslashes($uemail)."\" <".$uemail.">\r\n";
$headers   .= "MIME-Version: 1.0\r\n"; 
$headers   .= "Content-Type: text/html; charset=iso-8859-1\r\n"; 
$headers   .= "X-Priority: 1\r\n"; 
$headers   .= "X-Mailer: PHP / ".phpversion()."\r\n"; 
mail( $to, $msubject, $mbody, $headers ) or print "Error handling message. message not sent."; 
}
?>
The email to <?=$to?> (<?=$to?> ) Was send successfully.<br><br>
The message was: <?=$mbody?><br><br>

And the headers were: <?=$headers?>
</body>
</html>

dmyers
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Jun 24, 2003 11:55 am

Postby Flood » Wed Jun 25, 2003 10:33 am

Hej!

Try to put the value for the field in-between apostrophes
-->
$sql = "SELECT * FROM authuser WHERE email = '{$_POST['uemail']}'";

Hope it will solve the problem.

/Flood
Flood
New php-forum User
New php-forum User
 
Posts: 23
Joined: Tue Jun 24, 2003 4:49 am

That work, but still can not send mail

Postby dmyers » Wed Jun 25, 2003 10:40 am

Any idea what is wrong with this mail function?

Code: Select all

<?
if ( isset ( $_POST ["uemail"] ) ) {
@mysql_connect('localhost', 'gltanet_gltaadmi', 'gltaglta') or die(mysql_error());
@$result = mysql_list_tables('gltanet_gltauser') or die(mysql_error());

$sql = "SELECT * FROM authuser WHERE email = '{$_POST['uemail']}'";
@$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');

while ($row = mysql_fetch_row($result)) {
    // $tb_names[] = $row[0];
    // echo "System ID: ";
   // echo $row[0].'<br />';
   echo "First Name: ";
   echo $row[8].'<br />';
   echo "Last Name: ";
   echo $row[9].'<br />';
   echo "User Group: ";
   echo $row[3].'<br />';
   echo "Status: ";
   echo $row[5].'<br />';
   echo "Username: ";
   echo $row[1].'<br />';
   echo "Password: ";
   echo $row[11].'<br />';
   // echo "Encrypted Password: ";
   // echo $row[2].'<br />';
   // echo "Level: ";
   // echo $row[4].'<br />';
   // echo "Last Logon: ";
   // echo $row[6].'<br />';
   // echo "Logon Count: ";
   // echo $row[7].'<br />';
   echo "E-Mail Address: ";
   echo $row[10].'<br />';

      
   $username = $row[1];
   $firstname = $row[8];
   $lastname = $row[9];
   $password = $row[11];
   $email = $row[10];
   $group = $row[3];
   $status = $row[5];
   $uemail = $row[10];
}

$msubject = "Account information from GLTA";
$mbody .= "The account information you requested is displayed below.\n";
$mbody .= "\n";
$mbody .= "Username\t\t: $username \r\n";
$mbody .= "Password\t\t: $password \r\n";
$mbody .= "E-Mail\t\t: $email \r\n";
$mbody .= "User Group\t\t: $group \r\n";
$mbody .= "Access Level\t\t: $level \r\n";
$mbody .= "Status\t\t: $status \r\n";
$mheader = "From: GLTA Security";

$to  = "$uemail <$uemail>";
$headers = "From: \"".addslashes($uemail)."\" <".$uemail.">\r\n";
$headers   .= "MIME-Version: 1.0\r\n"; 
$headers   .= "Content-Type: text/html; charset=iso-8859-1\r\n"; 
$headers   .= "X-Priority: 1\r\n"; 
$headers   .= "X-Mailer: PHP / ".phpversion()."\r\n"; 
mail( $to, $msubject, $mbody, $headers ) or print "Error handling message. message not sent."; 
}
?>
The email to <?=$to?> (<?=$to?> ) Was send successfully.<br><br>
The message was: <?=$mbody?><br><br>

And the headers were: <?=$headers?>
</body>
</html>

dmyers
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Jun 24, 2003 11:55 am

Postby Flood » Wed Jun 25, 2003 10:52 am

Tell us what goes wrong... Don't you receive any mail? Do you get any PHP error?

/Flood
Flood
New php-forum User
New php-forum User
 
Posts: 23
Joined: Tue Jun 24, 2003 4:49 am

Postby dmyers » Wed Jun 25, 2003 11:02 am

I dont receive any email. I do receive a message, but it is incorrect, because I do not get any email.

---message--

Error handling message. message not sent. The email to dmyers@4-webdesign.net (dmyers@4-webdesign.net ) was sent successfully.

The message was: The account information you requested is displayed below. Username : 14298691 Password : atlantis E-Mail : dmyers@4-webdesign.net User Group : members Access Level : Status : active

And the headers were: From: "dmyers@4-webdesign.net" MIME-Version: 1.0 Content-Type: text/html; charset=iso-8859-1 X-Priority: 1 X-Mailer: PHP / 4.3.1
dmyers
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Jun 24, 2003 11:55 am

Postby Flood » Wed Jun 25, 2003 11:04 am

And are you sure you have set up the right SMTP server name and address?

Incidentally, it has nothing to see with your question, nor with PHP... but with HTML... Don't forget the tag <!DOCTYPE at the beginning of your script... Some navigators might guess it, but others don't...
cf. http://www.w3schools.com/tags/tag_doctype.asp (if html, not xhtml)

/Flood
Flood
New php-forum User
New php-forum User
 
Posts: 23
Joined: Tue Jun 24, 2003 4:49 am


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron