Hiya all.
I'm relatively new to PHP and am really struggling on this problem. What I am trying to do is -
User enters a login name(of another user)
-
Code then querys the MySQL database (using the login name from before), finds the email address of the login name specified
-
The result (email address) is then stored a varible and used in the contact form
I have done it this way so there is some form of security, I am not wanting to display email addresses.
All I am getting is the white page error? I think the 3rd if statment is causing is causing a problem but I am not sure why? I think this as when it is in the editor it is not the same color as the previous if statement, the following if statments arent the same color as the first two either. Is this an error or just because its nested?
Also am i going about this correct way? As i am newish to PHP im not totally convinced if I am doing things the right way.
Any help will be amazing.
Thanks, Stephen.
<?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;
}
$row = mysql_fetch_assoc($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>";
}
else if(!preg_match("/^.*?@.*?$/", $_POST['email']))
{
$messages = "You have not entered a valid email address. It must be in the format name@provider.com.<br>";
}
else
{
$subject = stripslashes(trim($_POST['subject']));
$message = stripslashes(trim($_POST['message']));
$headers = "From: " . $_POST['email'];
mail($sysmail, $subject, $message, $headers);
$messages = "Please wait for a response from the user you messaged.<br>";
}
}
?>
<form action="" method="post">
<span style="color:#FF0000; font-weight:bold;"><?php = $messages ?></span>
<table width="50%" border="0">
<tr>
<td width="50%" valign="baseline"><div id="cf-email" align="right">Your email Address: </div></td>
<td width="50%" valign="baseline"><input type="ext" id="email" name="email" size="50"/></td>
</tr>
<tr>
<td valign="baseline"><div id="cf-subject" align="right">Subject: </div></td>
<td valign="baseline"><input type="ext" id="subject" name="subject" size="50"/></td>
</tr>
<tr>
<td valign="top"><div id="cf-message" align="right">Message: </div></td>
<td valign="top"><textarea name="message" cols="50" rows="10" id="message"></textarea></td>
</tr>
<tr>
<td colspan="2" valign="top"><div align="center">
<input type="submit" value="Send Message">
</div>
</td>
</tr>
</table>
<input type="hidden" name="sendmessage" value="1">
</form>