I am a begginer at php, and am trying to write something that will check a MySQL database and then email the queryed results back to the user.
Below is what i have so far, and it doesnt work. Any help/suggestions/comments would be greatly appreciated.
Thanks,
Chris
-----------------user input form code(this page works)------------------
<form name="form1" id="form1" method="post" action="send_pass.php">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Email </font><br />
<input type="text" name="useremail" id="useremail" />
<input type="submit" name="Submit" value="Submit" />
</form>
-----------send_pass.php(this is the part that doesnt work)----------
<?
#connect to MySQL, and select the database
$db = mysql_connect('localhost','chrisrottmann','xxxxxxxx')
or die("Unable to connect to MySQL <br />".mysql_error());
mysql_select_db('chrisrottmann_com')
or die("Unable to connect to chrisrottmann_com <br />".mysql_error());
#catch and/or set variables_____________________________________________________________
#catch vars
$useremail = $POST["useremail"];
#set vars
$site_name = "chrisrottmann.com";
$myemail = "chrisrottmann@chrisrottmann.com";
$ip = $SERVER["REMOTE_ADDR"];
#_______________________________________________________________________________________
#start session
session_start();
#check if email is valid
if(!ereg("[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.([a-zA-Z]{2,4})$",$useremail
)){
#see http://www.sitepoint.com/articles/974/
$SESSION["err2"] = "Email Address Must Be Valid!";
header("Location:form.htm"); #redirect
}
#search db to find email________________________________________________________________
$sql = "SELECT * FROM login WHERE email='$email'";
$result = mysql_query($sql) or die("Query failed <br />".$sql."<br />".mysql_error());
#add collected info from db and add & send to email______________________________________
if(mail($useremail,$site_name." Password Response","Your information is ".$sql,"From:$myemail\r\nReply-to:$myemail\r\nReturn-Path:$myemail")){
$result .= "<br>Your user information has been sent to your email";
}
}
?>