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