/    Sign up×
Community /Pin to ProfileBookmark

JS or PHP? Best approach for form/database update

Hi,

Not sure if this goes in the JavaScript or PHP forum since it includes both, …

I have a MYSQL database that has a couple of tables into which a user needs to do the usual database stuff, CRUD.

I need to create a web page front end form to let all this happen. Should I be doing the form in JavaScript or PHP, or does it matter? As far as I know, only PHP can communicate with the db, so I’m guessing the submit (or update or add etc.) buttons each go to new php page that has the form values posted to it, and it db updates can’t happen once the page is loaded. Can JS run an external php file to do updates w/o loading a new page?

Each button needs a different page, so would JS handle this??

1) What’s the best approach to this?
2) Is there a good but not too complex sample of a php/JS form/db like this?

Thanks!

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@mrhooApr 17.2008 — Lots of sample code out there- google 'php mySQL AJAX' and take your pick.

Try to keep the brains of the outfit on the server, to make things a hair tougher for hackers.
Copy linkTweet thisAlerts:
@jayw710authorApr 17.2008 — Thanks, however sample code won't help me until I know which approach to take.
Copy linkTweet thisAlerts:
@TJ111Apr 17.2008 — If you want the page to not reload, you'll have to use Javascript (Ajax), but will still need PHP to work with the database on the backend. If you are ok with the page reloading everytime, it can be done entirely in PHP. "The choice is yours and yours alone" (mad respect to anyone who can name the reference).

If you do go the Ajax route, like mrhoo said, keep all the logic/etc on the server. Javascript is semi-easy to workaround, and it will make a crackers life (!hacker) easier if the logic is all available for them to read.
Copy linkTweet thisAlerts:
@felgallApr 17.2008 — You will need a version of the code that works without JavaScript so that the page functions for those of your visitors without it. Always get your page working without JavaScript first and then add the javaScript to enhance the way the page works for those who have it.
Copy linkTweet thisAlerts:
@jayw710authorApr 18.2008 — Hi,

Thanks for all the comments. I'll be fine w/ JavaScript since the part this is for is staff use, all of which have JavaScript.

I'm going with PHP for all the work and I'll just reload the pages.

Thanks again!
×

Success!

Help @jayw710 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...