如何从数据库中检索电子邮件,其中$ _POST var就像用户名一样

Here is the code

    <?php 
if(isset($_POST['uuser'])){
       $gemail = mysql_result("SELECT `email` FROM `user` WHERE `username` LIKE '" . ($_POST['uuser']) . "';");

    $to ="$gemail"; // this is user's Email address 

    $from = "admin@mysite.com"; // this is the sender's Email address
    $first_name = $_POST['uuser'];
    $last_name = $_POST['uuser'];
    $subject = "Form submission";

    $message = $first_name . " " . $last_name . " wrote the following:" . "

" . $_POST['message'];

    $headers = "From:" . $from;
    mail($to,$subject,$message,$headers);
    }
?>

The problem is with $gemail its not getting email from database.

You need to use mysql_query or mysqli_query. So below will be your code.

$con=mysqli_connect("localhost","my_user","my_password","my_db");
$user = mysqli_real_escape_string($con,$_POST['uuser']);
$gemail = mysqli_query($con,"SELECT `email` FROM `user` WHERE `username` LIKE '".$user."'");