Okay… So, I came across the following problem: I have one table that works properly – it holds users’ IDs, posts’ IDs, posts’ content, time that post was made.
I use it to have the following printed out: the content of the post, who is the author of the post and when the post was made. So far everything works just fine.
Now… I have a button that allows the users to vote up for a given post – everything is working just fine here as well. However, now I want to make one more feature that will show who and when has voted. You know, so that beneath each post there will be a list of people who have liked the post and when they’ve pressed the button.
My idea was to have two tables – the one holding the post’s info post_table, and one more table voted_table that will have the user IDs, the time the button was pressed and the post_id that the vote has been made for… But I have no idea how to actually make it.
So pretty much my question is:
How can I insert into a table information from another table + some other information on a button’s click?
So with the schema above we can do the following…
in your html/php for the
viewPostpage you could haveSo then in
votePost.phpyou could do something like:This way mysql will take care of the timestamp for you. Note that you need to verify/validate the input data (which i didnt really do here) before inserting it into the db and all that fun security stuff. Id also recommend using Mysqli or PDO Mysql instead of the old mysql libararies and using a prepared stament (that will take care of most of your value quouting/escaping functionality on its own)