What i am trying to do is query the database to find the email address, which i have managed to do. Then i want to use the values in the variable to use in a form that will email them. This is what I have got so far, any help would be amazing because I am so stuck with it.
Code: Select all
<?php
$username=($_POST['username']);
echo "User selected = $username";
include ('connect.php');
mysql_select_db("a6188092") or die(mysql_error());
$sql = ("SELECT email FROM Member WHERE loginName='$username'");
$result = mysql_query($sql);
if (!$result)
{
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0)
{
echo "No rows found, nothing to print so am exiting";
exit;
}
while ($row = mysql_fetch_assoc($result))
{
echo $row["email"];
}
//mysql_free_result($result);
$sysmail = $row["email"];
if ($_POST['sendmessage'])
{ if(!isset($_POST['message']))
{
$messages = "You have not entered a message. Please enter a message in the comments box below and submit.<br>";
}
elseif(!preg_match("/^.*?@.*?$/", $_POST['email']))
{
$messages = "You have not entered a valid email address. It must be in the format name@provider.com.<br>";
}
elseif(mail($sysmail, stripslashes(trim($_POST['subject'])), stripslashes(trim($_POST['message'])), "From: " . $_POST['email'] . "\r\n"))
{
$messages = "Please wait for a response from the user you messaged.<br>";
}
else
{
$messages = "Error. Please contact the administrator.<br>";
}
?>