php - 获取变量数组的数据库数据

标签 php html mysql arrays foreach

您好,我创建了一个功能,使用上一页上的复选框选择的预约空档时间将添加到我的数据库中,同时存储空档时间 存储起来,以便可以在我的邮件功能中的页面下方使用它们。

$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;
}

我现在需要使用用户选择的时段来识别插入数据库时​​自动生成的预约号码,我尝试使用的代码如下:

        $insertedapps = mysql_query("SELECT * FROM appointment 
        WHERE Appointment_Date='".$insertdate."' 
        AND Appointment_Time='".$key."'");
        while($row3 = mysql_fetch_array($insertedapps))
    {   $appno = $row3['Appointment_No.'];
    }

邮件功能:

$to = "$pemail";
       $subject = "Booking Confirmation";
       $message = "Hello $pfname 
       This e-mail is to confirm your $appname appointment has been booked for the below times for $insertdate at the the following time(s) below:
       Appointment No:      Appointment Time:
       $appno[0]            $savedData[0]
       $appno[1]            $savedData[1]
       $appno[2]            $savedData[2]
       $appno[3]            $savedData[3]
       The above appointment(s) are booked at the $pracname practice
       Should you wish to alter this appointment please login via our customer login page or contact us on $pracphone";
       $from = "xxxxx@xxxx.xxxx";
       $headers = "From:" . $from;
       mail($to,$subject,$message,$headers);
       echo "Mail Sent.";

预约时间打印得很好,但我没有得到预约号码的结果...有人可以指出我哪里出错了吗?

最佳答案

$appno = $row3['Appointment_No.'];

每次都会重新初始化 $appno 变量。因此它永远不会包含 4 个值,请使用 $appno[]

另外,$row3['Appointment_No.'] 是什么?我假设它是一个 auto_increment 字段,但正如评论中指出的那样,那个句点 . 不能在那里。也许是拼写错误?

关于php - 获取变量数组的数据库数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15247447/

相关文章:

php - mySQL SELECT AS 用于多个条件

php - 建议使用 PHP 编写不显示产品价格的产品目录脚本/框架

javascript - Javascript 中没有数据通过 FileReader 传递

php - 没有从数据库返回属性?

mysql - 具有特定条件的 VIEW SQL 上的三个表的 JOIN 和 SUM

php - WordPress 全 Angular 页脚

php - 有没有一种聪明的方法可以在用分号分隔的 mysql 中运行多个查询?

php - 使用 PHP 将混合数据从数组输入 MySQL 数据库

php - MYSQL + PHP 将两行数据显示为单列

html - 在 ASP.net 中动态生成 HTML 表格会导致严重的性能问题吗?