MySQL Forums
Forum List  »  PHP

one to many PHP app - Query problems
Posted by: Adam Grey
Date: March 11, 2021 10:54AM

Hello! I hope I am in the right spot for some help with a PHP web app I am developing. It's basically a day planner. I am getting information from a PHP/HTML form.

So I have 2 tables a users (primary) and an events.

Users has fields: id( Auto increment/primary key/), username (unique/index), password (hashed), and email (index/unique)

(one to many relationship)

My events table has: id (primary key/index (Is this necessary?)), user_id (index/foreign key to ), title(varchar), description(varchar), dateHappens(date) and createdOn(date)

So I hope I got the table set up right. I have the id of users to be primary and user_id of events to be foreign.

What is giving me problems:
So the dateHappens field is a date input by the user of an upcoming event.
createdOn is a field that stores the current date information

I am having trouble getting all of the events table information into the database. - The query is wrong.

Here is my current query, I hope this is sufficient information to get some help.

"INSERT INTO events(title, description, dateHappens, createdOn) VALUES(?,?,?,?)";

and I am trying to insert the data like this:

($user->getTitle(), $user->getDesc(), $user->getHappens(), NOW()));

Not sure how to get the foreign key of user_id from the primary key in the users table. In the sql query how do I get the referenced id primary key in the events table data?

Thanks for any help!

Options: ReplyQuote

Written By
one to many PHP app - Query problems
March 11, 2021 10:54AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.