0

我想让 php 将 productsq 复选框作为数组并在消息中发送

这不是代码它只是它的一部分

这是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']));
4

2 回答 2

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>";
于 2013-02-18T12:15:07.797 回答
0

根据您的复选框

$_POST['productsq']是一个数组。

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

因此,首先将数组内爆成字符串,然后mysql_real_escape_string()在其上使用。

于 2013-02-17T22:35:32.870 回答