首页 > 解决方案 > 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";
    }

标签: phpsqlms-access

解决方案


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";


推荐阅读