2013-02-17 53 views
0

我想使PHP採取productsq複選框作爲數組和消息PHP發送消息包括複選框陣列

發送過來這不是代碼,它只是其中的

的一部分,這是HTML部分

<input type="checkbox" id="productsq" name="productsq[]" value="cardprinter"/> <input type="checkbox" id="productsq" name="productsq[]" value="hotelsolution"/ >

這是PHP部分

<?php 
    $productsqu= implode(',',mysql_real_escape_string($_post['productsq'])); 
    $message = '<html><body>'; 
    $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">'; 
    $message .= "<tr style='background: #eee;'><td><strong>products:</strong> 
    $message .= "<tr style='background: #eee;'><td><strong>comments:</strong> </td> <td>" .clean_string($_POST['comments']) . "</td></tr>"; 
    $message .= "<tr style='background: #eee;'><td><strong>selectionField:</strong> </td><td>" .clean_string($_POST['selectionField']) . "</td></tr>"; 
    $message .= "<tr style='background: #eee;'><td><strong>products:</strong> </td><td>" .clean_string($productsqu) ."</td></tr>"; 
    $message .= "</table>"; 
    $message .= "</body></html>"; 
?> 

我也嘗試過使用這個,但它沒有奏效,有沒有辦法讓它正常工作?

$productsqu= implode(',',mysql_real_escape_string($_post['productsq'])); 
+0

我知道 是這樣工作 $ productsq =破滅的溶液( ' '$ _ POST [' productsq']); – 2013-02-17 22:39:43

回答

0

根據您的複選框

$_POST['productsq']是一個數組。

$productsqu = mysql_real_escape_string(implode(", ", $_POST['productsq'])) ; //Implode into string first 

因此,首先將數組爆炸成字符串,然後使用mysql_real_escape_string()就可以了。

0

嘗試下面的代碼希望它會幫助你。

<?php 
if(isset($_POST['submit']) == 'submit') 
{ 
     $productsqu= mysql_real_escape_string(implode(',',$_POST['productsq'])); 
     $message = '<html><body>'; 
     $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">'; 
     $message .= "<tr style='background: #eee;'><td><strong>products:</strong>"; 
     $message .= "<tr style='background: #eee;'><td><strong>comments:</strong> </td> <td>" .$_POST['comments'] . "</td></tr>"; 
     $message .= "<tr style='background: #eee;'><td><strong>selectionField:</strong> </td><td>" .$_POST['selectionField']. "</td></tr>"; 
     $message .= "<tr style='background: #eee;'><td><strong>products:</strong> </td><td>" .$productsqu."</td></tr>"; 
     $message .= "</table>"; 
     $message .= "</body></html>"; 
    echo $message; 
} 
?> 

並且在下面的行中也有";丟失。

$message .= "<tr style='background: #eee;'><td><strong>products:</strong>";