mysql - Inserting reservation record to php database -
i have created reservation form housing. user fills form out , submits it. reservation record supposed made inserted reservations table.
this code being inserted database record
$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"]]);
these functions transform data:
function createrecord($table, $values) { echo "this working"; return insertinto($table, ["name","class","specialneeds","laundry","fullyequippekkitchen","roomsavailable","roomsreserved","roomcapacity"], $values); } function createreservationrecord($table, $values) { echo "<br> in createreservationrecord(), table \"$table\", values ".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 $table (" . implode(", ", $columns) . ") values (" . implode(", ", $values) . ")"; echo "inserting new record sql statement: $sql\n<br>"; return query($sql); }
when use print_r($values) check array of values returns 1. i'm not sure why data being inserted being read wrong.
change here , use tick in cumn , single quotes in values
$sql = "insert $table (`" . implode("`, `", $columns) . "`) values ('" . implode("', '", $values) . "')";
Comments
Post a Comment