dongling2038 2014-05-21 21:16
浏览 57
已采纳

如何从sql数据库表中获取列数据并将该数据放入PHP中的字符串中?

I am trying a lot but nothing work for me.

My query is that how to fetch column data from sql database Table and put that data into an string in PHP?

Please check What I am doing.

I have the table "DriveRegisterTable" in which 4 columns in database table, 1st "id" 2nd "username" 3rd "txtMail" 4th "rxtMail" .

Now I want to select txtMail and rxtMail from database table where username = "John"

Now in my database table "username" john have txtMail is " johnery99@gmail.com" and rxtMail is "sarah88@gmail.com"

Now I want to fetch these thing on my php string.

Now I want to select txtMail and rxtMail from database table where username = "John" and put txtMail and rxtMail values which are johnery99@gmail.com and sarah88@gmail.com in PHP String and then send the mail.

Please check what I am doing it is not working for me:

<?php


$db_host  = "localhost";
$username = "jacktask";
$db_pass  = "sormor4455";
$database = "myDatabaseDB";

mysql_connect("$db_host", "$username", "$db_pass");

@mysql_select_db($database) or die("Unable to find database4");

$txt_username          = $_REQUEST['txt_username']; // here user name is John


$query  = mysql_query("SELECT txt_email,rxt_email FROM DriveRegisterTable WHERE txt_username ='$txt_username'");


//$sql = "SELECT txt_email,rxt_email FROM DriveRegisterTable WHERE txt_username ='$txt_username' ORDER BY id ";
$res = mysql_query($query);


if($query){    // Dont know how to send mail or what to write in this condition block


$to      = $txt_Mail;      // want johnery99@gmail.com here only but not able to fetch this mail here
$subject = 'Hello Subject!';
$message = 'Hi';
$headers = 'From: $txt_email' . "
" .
'Reply-To: txt_email' . "
" .        // want sarah88@gmail.com here but txt_email does not give any value here means sarah88@gmail.com
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

}


mysql_close();

?>

I just want to select johnery99@gmail.com and sarah88@gmail.com from John and send mail.

Any Idea or suggestions would be highly welcome.

  • 写回答

2条回答 默认 最新

  • doucheng1063 2014-05-21 21:21
    关注

    Youre going to loop through your query

    also your $res is redundant, its better to remove that

    if($query){    // Dont know how to send mail or what to write in this condition block
    
     while ($row = mysql_fetch_array($query)) {
       $txt_Mail = $row['txtMail'];
       $rxtMail = $row['rxtMail'];
    
       $to = $txt_Mail;  // want johnery99@gmail.com here only but not able to fetch  
       $subject = 'Hello Subject!';
       $message = 'Hi';
       $headers = 'From:'. $rxtMail .' . "
    " .
      'Reply-To: '. $rxtMail .' . "
    " .        // want sarah88@gmail.com here but txt_email  does not give any value here means sarah88@gmail.com
      'X-Mailer: PHP/' . phpversion();
    
       mail($to, $subject, $message, $headers);
    }
    
    }
    

    next time, try to use mysqli (Mysql Improved) or PDO. mysql functions is deprecated and for the future it wont be supported anymore

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求