0

I'm currently working on a website which allows the costumer to personally add movies to a database. So I wrote a PHP class which initially loads all the data needed from a database and creating a table which kind of looks like this:

My Question now:

How do I theoretically proceed to make those buttons work(Which, as they change things in a database should "execute" php-functions).

Narayan
  • 1,670
  • 1
  • 19
  • 37
trpouh
  • 175
  • 2
  • 11
  • 1
    Possible duplicate of [Call php function from javascript](https://stackoverflow.com/questions/7165395/call-php-function-from-javascript) – Don't Panic May 26 '17 at 19:30

1 Answers1

0

theoretically this is how you should proceed:

First the database piece

  1. you will create 4 fields
    • each field corresponding to the table header (notice there should be no space in the name of the field) -- movie_id will be numerical, name will be varchar, etc.

Next the code

  • I take it the second row are all inside tag? if not make it so
  • Make sure the form method is POST
  • I recommend making the action of the form go to another page (keeps it clean)

user clicks on "save changes" button

  • On the other page (specified in form action), you will receive the data in your $_POST var; based on each input's name, this will be accessible in post. So for example, if your input name for "name" field is "movie_name" then this data will be in: $_POST['movie_name']
  • Store each field's POST data in a variable... i.e. $movieName = $_POST['movie_name'] ---- THIS IS JUST AN EXAMPLE! YOU SHOULD NEVER ACCESS POST DATA DIRECTLY!! YOU MUST SANITIZE/VALIDATE ETC. THIS DATA BEFORE STORING IN DATABASE
  • Assuming you have a database link already established, simply insert the data into the table you created earlier

Hope this helps you get started!

Best,

-Rush

Rushikumar
  • 1,774
  • 5
  • 18
  • 28
  • my pleasure; just post to this thread if you get stuck at any point... some steps above were left intentionally vague for you to explore. – Rushikumar May 26 '17 at 19:46