Difference between revisions of "PHP 101"

From ESE205 Wiki
Jump to navigation Jump to search
m (Ethanshry moved page Creating a PHP File to PHP 101: Fall 2018 Wiki Reworks)
 
(12 intermediate revisions by 3 users not shown)
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.png|800px|200px]]
+
[[File:databaselogin.png|1600px|600px]]
  
 
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.
  
[[File:pictable.png|800px|200px]]
+
[[File:Table1.png|1000px|600px]]
  
 
== Creating a PHP File to Get An Item ==
 
== 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.  
+
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. To view the exact code we used, visit https://github.com/maggiearcher/GroceryGuru/blob/patch-1/service.php.
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.
+
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. The first line uses the hostname, database username, password, and database name. 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
+
 
 +
[[File:service.png|800px|488px]]
  
 
== Creating a PHP File to Edit a Row of the Table ==
 
== 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.
+
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. Visit this webpage to view the code: https://github.com/maggiearcher/GroceryGuru/blob/patch-1/combine.php
 
 
photo of php file
 
  
 
== Testing the PHP Files ==
 
== 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.
+
In order to check whether the code in your PHP files has 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 failing.
  
  
 
[[Category:HowTos]]
 
[[Category:HowTos]]
 +
[[Category:Web_Development]]
 +
[[Category:Programming]]

Latest revision as of 03:27, 17 August 2018

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.

Table1.png

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. To view the exact code we used, visit https://github.com/maggiearcher/GroceryGuru/blob/patch-1/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. The first line uses the hostname, database username, password, and database name. 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.

Service.png

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. Visit this webpage to view the code: https://github.com/maggiearcher/GroceryGuru/blob/patch-1/combine.php

Testing the PHP Files

In order to check whether the code in your PHP files has 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 failing.