2012-04-12 41 views
0

我有這樣的代碼連接到MySQL,並從一個表中獲取數據:MySQL數據,形成用PHP

<?php 

    //Include database connection details 
    require_once('sql/config.php'); 

    //Connect to mysql server 
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); 
    if(!$link) { 
     die('Failed to connect to server: ' . mysql_error()); 
    } 

    //Select database 
    $db = mysql_select_db(DB_DATABASE); 
    if(!$db) { 
     die("Unable to select database"); 
    } 

    $result = mysql_query("SELECT * FROM customers"); 

    while($row = mysql_fetch_array($result)) { 
     echo $row['email']; 
     echo "<br />"; 
    } 

    mysql_close($link); 
?> 

現在,我怎麼填這個電子郵件數據從MySQL到這是創建以前安全的形式?

+3

我不明白你的問題... – Marco 2012-04-12 13:11:46

+0

你的代碼似乎沒問題。你想完全填寫什麼?更好地解釋 – ShinTakezou 2012-04-12 13:12:25

+0

我想將id row ['email']放在ID爲 – 2012-04-12 13:20:03

回答

0

變化

while($row = mysql_fetch_array($result)) { 
     echo $row['email']; 
     echo "<br />"; 
    } 

到:

while($row = mysql_fetch_array($result)) { 
     $emails_array[] = $row['email']; 
    } 

然後使用$emails_array爲:

$people_to_email_to = implode(";", $emails_array); 

那麼你的表格:

echo "<input id='emails' type='text' value='$people_to_email_to' name='emails' />";