2

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.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Livia Mano
  • 23
  • 4
  • I didn't think there is any problem in that. – urfusion Jan 19 '16 at 11:12
  • 2
    Please don't use "mysql_*" statements because they are deprecated: [See here](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Y.Hermes Jan 19 '16 at 11:14
  • No need to worry. You can continue with this way. it will not harm your security as well. – Makwana Ketan Jan 19 '16 at 11:15
  • @RiggsFolly No, this is a feature request. – Mast Jan 19 '16 at 11:15
  • 1
    @Y.Hermes yes I know, I am changing all my mysql statements to mysqli, I will change this one too. Just needed to make sure I'm on the right track with the rest of the code – Livia Mano Jan 19 '16 at 12:41

0 Answers0