我已經創建了一個房屋預訂表。用戶填寫表格並提交。應該預訂記錄,然後插入到保留表中。將預定記錄插入到php數據庫中
這是正在被插入到數據庫中作爲記錄代碼
$reservationsTable = "Reservations";
$r1 = (rand(11111,99999));
createReservationRecord($reservationsTable, [$r1, $date,$dormRecord[id], $_POST["CWID"], $_POST["firstName"], $_POST["lastName"], $_POST["class"], $_POST["gender"], $_POST["fullyEquippedKitchen"], $_POST["laundry"], $_POST["specialNeeds"]]);
這些是該數據變換功能:
function createRecord($table, $values) {
echo "This is working";
return insertInto($table, ["name","class","specialNeeds","laundry","fullyEquippeKkitchen","roomsAvailable","roomsReserved","roomCapacity"], $values);
}
function createReservationRecord($table, $values) {
echo "<br> in createReservationRecord(), table is \"$table\", values are ".print_r ($values)."\n<br>";
return insertInto($table, ["id","reservationTime","ra_id","CWID","firstName","lastName","class", "gender","kitchen", "laundry", "specialNeeds"], $values);
}
function insertInto($table, $columns, $values) {
$sql = "INSERT INTO $table (" . implode(", ", $columns) . ") VALUES (" . implode(", ", $values) . ")";
echo "Inserting a new record with SQL Statement: $sql\n<br>";
return query($sql);
}
當我使用的print_r($值)到檢查值的數組它只返回1.我只是不知道爲什麼被插入的數據被讀錯了。
使用反勾中的CuMn和單引號爲什麼數據庫抽象的這麼多lavels?在做完所有的事情之後,你將自己開放給SQL注入。刪除所有這些,並使用PDO – e4c5
這只是因爲我可以看到它插入的數據,當我確定沒有錯誤時,我可以壓縮代碼。 – Katie
將工作翻倍和三倍以產生錯誤代碼。第一次做對吧 – e4c5