I'm working on a website that allows users to search for rooms to rent. the users also can 'upload' a new house, once logged in (similar to airbnb) What I'm looking for is a way to save in the house table the user's id, along with other house info like adress, city, rooms ect, which will be gained from a form. So far I've build the database like this
CREATE TABLE `house` (
`house_id` int(11) NOT NULL AUTO_INCREMENT,
....... (other house details),
`user_id` int(11) DEFAULT NULL,
PRIMARY KEY (`house_id`),
KEY `house_user_user_id_fk` (`user_id`),
CONSTRAINT `house_user_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`),)
So far I've tried to do something like this
if(isset($_SESSION['user_id'])) {
if (isset($_POST['listhouse'])) {
$user_id = $_SESSION['user_id'];
# input from form stored in variables
$query = "INSERT INTO house(price,title,description, city,street,user_id)
VALUES('$price','$title','$description','$city','$street','$user_id')";
$res = mysql_query($query);
if (!$res) {
die('something went wrong' . mysql_error());
} else {
header("Location: profile.php");
}
}
}
I need a way to relate a certain house with a certain user.