php - How can I insert into a table both a select max function from another table and variables input by the user, using PHP, SQL and Microsoft Access?
问题描述
I want to insert a record into the Booking_Sheet table when the user enters their information on an HTML document. First, some of the information is stored in the Client_Database table, and then I want the rest of the information to be stored in the Booking_Sheet but I want the record on the Booking_Sheet to contain information that was just inserted, such as the AutoNumber Client_ID from Client_Database, which I am doing with a select max statement. Although this is not working. I was wondering if it is possible to have a SELECT statement imbedded within VALUES?
$sql="INSERT INTO Booking_Sheet (Client_ID, Client_Name)
VALUES ((SELECT MAX(ID) FROM Client_Database), '$name');";
if(odbc_exec($con,$sql))
{
echo "<br>Data saved<br>Please Wait Page redirect..";
header("refresh:1;url=index.php");
}
else
{
echo "Error";
}
解决方案
Apparently not. I just tried within Access and it fails. However, don't need VALUES.
"INSERT INTO Booking_Sheet (Client_ID, Client_Name) SELECT MAX(ID), '$name' FROM Client_Database";
推荐阅读
- botframework - 覆盖 Bot Composer 中的默认语言设置
- bash - docker如何启用ssh连接
- php - yii2 从控制台运行模块命令
- python - 使用 cvxpy 实现 SVM
- python - YouTube 流媒体的 Google API userRequestsExceededRateLimit
- json - 数据库中的多对多表不适用于弹性搜索
- python - 静态是唯一可以用 URL 直接访问的目录吗
- javascript - 给定一个字符串 S,返回“反转”字符串,其中所有不是字母的字符都留在同一个位置,并且所有字母反转它们的位置
- google-chrome - Google Docs 表格单元格在编辑时突然不自动换行
- mesh - Threejs 从网格中切割相交网格