Jump to content

Recommended Posts

I am creating a scheduling webpage where users can schedule meetings in a calendar, and have just gotten to writing the backend. The front end is basically complete, and I have created a database for it, but I am not sure how/where my HTML and PHP should interact. Currently, I have an html file (my index) and 3 javascript files that help with some dynamic features on my page. I know the code I need to INSERT, RETRIEVE, UPDATE, and DELETE from my database using PHP, but I am not sure WHERE this should go? 

 

Should I have a separate php file with functions I call from my HTML file? For example, if I want to update a table with a meeting time and meeting description, should I make a function in a database.php file: function updateMeeting(meetingTime, meetingDescription) { ..... } and call database.updateMeeting(meetingTimeData, meetingDescriptionData); from my HTML file?

 

Or should I put all my HTML information into a php file and just intersperse snippets of php to manipulate the database?

 

Basically: Where do I put the php code to work with my database for my webpage?

 

I understand I am a beginner and may have some false assumptions even in my question, so please bear with me! Thank you

Create a file called index.php.  In it, include something like:

$task=empty($_GET['task'])?'display':$_GET['task'];
switch($task) {
case 'display':
/* Get data from your database.
   Pass the data to your view.
   Use a proper template system for your view such as http://twig.sensiolabs.org/ to render a template.
   Your template should include links to your JS files.
*/
break;
case 'update_something':
//do something
break;
default: //Do the same as display

and what is the issue you are facing exactly with those codes? inside the case whichever way you wish you can insert update or delete data from db. be it through calling a function or straight away but make sure u define id related to your post.

Edited by lovephp

I call from my HTML file?

When you refer to a "html file" what exactly do you mean? Is it a file with a name ending in .html? Or is it a file that only has HTML code in it? Either way - unless you have configured your server to parse HTML extensions no code in that file can "call" anything.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.