1

嗨,我目前有一些 PHP 代码,它们会将先前从上一页的复选框中选择的时间段放入我的数据库中,但我不确定在执行此操作之前如何将每个时间段存储在一个变量中,以便我可以使用它们来列出预约空档在我的电子邮件功能中

在我尝试将'$key'插入我的电子邮件功能时,它只保留最后选择的值......

我在第一页上的代码如下:

<?php
for ($i=0;$i<=31;$i++){ while ($myrow = mysql_fetch_row($result)) {
printf("<tr><td>%s</td><td>%s</td></tr>\n",
$myrow[0]);
}

echo "<td><input type='checkbox' name='$displayTime2' onclick='KeepCount()'></td>";
echo "<td>$pagetime</td>"; ?>

我目前的代码如下:

<?php
foreach ($_POST as $key=>$value)
{
    echo $key; // show times selected on previous page
    mysql_query("INSERT INTO appointment(Patient_ID, Appointment_Date, Appointment_Time
                , Practice_ID, Appointment_ID)
                VALUES('$patid','$insertdate','$key','$pracid','$apptype')");   
}
?>

我的邮件功能如下:

   $to = "$pemail";
   $subject = "Talking Teeth Check Up Booking Confrmation";
   $message = "Hello! This e-mail is to confirm your ".$appname." appointment has been
   booked for ".$insertdate. " at ".$key." at the ".$pracname." practice";
   $from = "talkingteethdentists@talkingteeth.co.uk";
   $headers = "From:" . $from;
   mail($to,$subject,$message,$headers);
   echo "Mail Sent.";
4

1 回答 1

0

虽然上面的评论是对的,但让我来帮助你。

首先,您需要确定选择了哪些复选框,因此请执行一些 IF 语句来确定foreach循环内的每个复选框。

尝试这样的事情:

<?php
$savedData = array();
foreach ($_POST as $key=>$value){
    $key = mysql_real_escape_string($key);
    echo($key. "<br>"); // show times selected on previous page
    mysql_query("INSERT INTO appointment(Patient_ID, Appointment_Date, Appointment_Time
                , Practice_ID, Appointment_ID)
                VALUES('$patid','$insertdate','$key','$pracid','$apptype')");   

    //To save the variables for later:
    $savedData[] = $key;
}
?>

现在您可以使用 $savedData[0] .... $savedData[1] ... $savedData[2] .... 等访问我们所有的 KEY。

因此,您的电子邮件功能可能如下所示:

foreach($savedData as $time){
   $to = "$pemail";
   $subject = "Talking Teeth Check Up Booking Confirmation"; //mis-spelled confirmation =)
   $message = "Hello! This e-mail is to confirm your ".$appname." appointment has been
   booked for ".$insertdate. " at ".$time." at the ".$pracname." practice";
   $from = "talkingteethdentists@talkingteeth.co.uk";
   $headers = "From:" . $from;
   mail($to,$subject,$message,$headers);
   echo "Mail Sent.";
}

因此,这将为里面的每件作品发送一封电子邮件$savedData——如果这确实是意图的话。

于 2013-03-05T22:32:25.100 回答