macloo / sockmarket

Intro to MySQL and PHP for students

Home Page:https://weimergeeks.com/sockmarket/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sock Market

This is a simple database application for beginners. It uses:

  • A MySQL database
  • HTML5 forms
  • Vanilla JavaScript with fetch()
  • PHP scripts to connect to the database and write new data into the database

This application can:

  • Create a new record and add it to the database
  • View all records in the database
  • Update an existing record
  • Delete an existing record

As an exercise in a web development course, this is the students' second experience with PHP and MySQL.

Supplemental docs (Google docs):

You can try the live application here.

PHP without JavaScript

Because of an earlier assignment in the course, the Sock Market uses JavaScript to enter a new record into the database. The form is in the file enter_new_record.php. The JavaScript file called on submit is js/enter.js. That JavaScript file communicates with enter.php on the server, which sends a response back to js/enter.js, which in turn rewrites the HTML in enter_new_record.php.

It's possible to eliminate the JavaScript in that process and just use PHP instead.

The alternative files enter_new_record_NOJS.php and enter_NOJS.php provide all the changes necessary to eliminate the JavaScript, reducing three files to two. You can try it out.

The code in enter_new_record_NOJS.php has very few differences from the code in enter_new_record.php.

However, you can see a larger number of differences in enter_NOJS.php if you compare it with enter.php. You'll see that a lot of HTML was added to enter_NOJS.php to make it work as the response page.

In the original enter_new_record.php, when the server returns a response saying that the new record has been written to the database (or not), the JavaScript there would write that response text directly into the HTML — and also hide the form. The response message would appear on enter_new_record.php.

If you look at the browser address bar after you submit a new record with enter_new_record_NOJS.php instead, you'll see that the response is on enter_NOJS.php and NOT on the original form page.

File permissions on the server

If you're getting a 500 internal server error on a PHP file at your hosted website, it could be because of a permissions problem. Make sure all folders in your app have 755 and all files have 644.

.

About

Intro to MySQL and PHP for students

https://weimergeeks.com/sockmarket/

License:MIT License


Languages

Language:PHP 60.8%Language:JavaScript 13.7%Language:CSS 10.6%Language:Hack 10.4%Language:HTML 4.6%