Use a query variable to email user

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ruste blade
Forum Newbie
Posts: 2
Joined: Fri Apr 03, 2009 9:27 am

Use a query variable to email user

Post by ruste blade »

Hiya. Im really stuck on this problem, ive spent all day on it and its driving me mad! Ive only really just started using PHP so im struggling.
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>";
            }
        
        ?>
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: Use a query variable to email user

Post by mattpointblank »

What error(s) does that script give?
ruste blade
Forum Newbie
Posts: 2
Joined: Fri Apr 03, 2009 9:27 am

Re: Use a query variable to email user

Post by ruste blade »

Just the white screen/page. :banghead:
Post Reply