In an attempt to learn PDO I am using the sakila database to set up prepared inserts, selects, updates etc along with using a PDO connection in a class. I am using php and WAMP
What I am doing: I am trying to submit a form using the class and a method as the action. I also need to reference the class/method in the Ajax URL. Getting data from the class method to display is easy. I do not know how to use it with forms.
I have read/watched tons of tutorials but all reference the data coming into the class, but never how it got there from the form.
I know that to use a class in a page you must do it like this
$class=New Class();
$class->method();
How do you translate that to a form action and a URL in ajax?
<form action="CLASS/METHOD" method="POST" id="addmail">
$.ajax({
type: "POST",
url: "CLASS/METHOD",
data: data,
Ive no problem with jquery, it is submitting the correct form inputs in an alert after serialization. I am just lost on this one action that I cant find the answer to any wheres.
Thank you for your consideration, I hope I presented this clearly
EDIT if this cannot be done with a class, could you just reference a function as in
action "<?php insert();?>"
So as opposed in my comments, I’d go this way:
In Your index.php watch for URL like mentioned in comment above and if present (e.g.
/user/create/) just instantiatenew Userand call it’s methodcreate(). Nothing more trivial I could suggest. Better if You place that in someroutes.phpscript where You can handle more of these actions…PS: now I’m not sure why suggest this in answer when You decided to forget about classes and go with procedural PHP…
My opinion: Go with OO PHP, procedural PHP is relic.