Difference between revisions of "PHP 101"

From ESE205 Wiki
Jump to navigation Jump to search
Line 9: Line 9:
 
Create a new database on Bluehost and set up a user to access the database.
 
Create a new database on Bluehost and set up a user to access the database.
  
[[File:databaselogin.jpg|thumbnail]]
+
[[File:databaselogin.png|800px|200px]]
  
 
Use phpMyAdmin, the built-in app on Bluehost, to create a table in the database. Set columns and insert rows into the database.
 
Use phpMyAdmin, the built-in app on Bluehost, to create a table in the database. Set columns and insert rows into the database.

Revision as of 17:10, 2 May 2017

Grocery Guru

Description

In order to establish a connection between an application and the SQL database, a server must be used. For this tutorial, we used Bluehost to create a web domain, a database, and a database user. With this information, we can write PHP files to establish a connection to the database and provide the ability to update or change the items in the table of the database.

Setting Up the Database

Create a new database on Bluehost and set up a user to access the database.

Databaselogin.png

Use phpMyAdmin, the built-in app on Bluehost, to create a table in the database. Set columns and insert rows into the database.

photo

Creating a PHP File to Get An Item

Use the file manager in Bluehost to create a new PHP file in the public-html folder. Name the file with .php at the end. After creating the file, click to highlight it and use the code editor in the tool bar at the top to start writing code. photo of service.php The above code establishes a connection with the database, creates an array of each row in the table, and displays them on your domain with the directory /service.php. In your case, change "service" to the name of your file. The webpage is parsed as a JSON file in Xcode to search the database for a specific UPC number or variable in the table. photo of webpage

Creating a PHP File to Edit a Row of the Table

Follow the same instructions as before to create a new PHP file in the public-html folder. This file will be used to edit certain values of a row in the table using an SQL query.

photo of php file

Testing the PHP Files

In order to check whether the code in your PHP files have errors, use the Chrome applet Postman. Try to send a post request to change the values of a row. The echo statements in the PHP files should indicate where your code is going wrong.