You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,9 @@ There are multiple methods of retrieving data from a MySQL database using PHP. F
10
10
11
11
## Steps
12
12
13
-
1. Open up PHPMyAdmin.
13
+
1. Open up phpMyAdmin.
14
14
15
-
If you're using a local server phpMyAdmin can usually be accessed by starting your server and then clickong on the phpMyAdmin link. If you're using a hosting account there will be a link to phpMyAdmin in your control panel.
15
+
If you're using a local server phpMyAdmin can usually be accessed by starting your server and then clicking on the phpMyAdmin link. If you're using a hosting account there will be a link to phpMyAdmin in your control panel.
16
16
17
17
Once you have phpMyAdmin open, click on the import tab and select the `links.sql` file from this repository. This will create a table called `links` and populate it with some sample data.
18
18
@@ -35,13 +35,15 @@ if (!$connect)
35
35
?>
36
36
```
37
37
38
-
The first line of PHP will initiatie a connection. The `mysqli_connect` function requires a host, username, password, and database name. If you are using a local PHP server link MAMP or WAMP your host is `localhost` and your username and password are likely both `root`. This may vary depending on how you set up your local host. The database name will be whataver you named your database, if you don't have one go ahead an create one.
38
+
The first line of PHP will initiatie a connection to your MySQL server. The `mysqli_connect` function requires a host, username, password, and database name.
39
39
40
-
If you are using a hosting account then your MySQL user and database will need to be created in your hosting control panel. There is likely help in your control panel on what to use for your host.
40
+
If you are using a local PHP server link MAMP or WAMP your host is `localhost`and your username and password are likely both `root`. This may vary depending on how you set up your local host. The database name will be whataver you named your database. If you don't have one go ahead an create one.
41
41
42
-
The second part of teh above code will display an error message if the MySQL connection failed.
42
+
If you are using a hosting account, your MySQL user, password, and database will need to be created in your hosting control panel. There is likely help in your control panel on what to use for your host.
43
43
44
-
> Hint: It would be a good idea to test at thi point, nothing else below will work if your MySQL connection isn't working.
44
+
The second part of the above code will display an error message if the MySQL connection fails.
45
+
46
+
> Hint: It would be a good idea to test at this point, nothing else below will work if your MySQL connection isn't working.
45
47
46
48
> [More information on PHP and `mysqli_connect()`](https://www.php.net/manual/en/function.mysqli-connect.php)
The first block of PHP will create and execute an SQL statement. If this query is successful then inside the `$result` variable will be a list of links. The next block of code will display an error message if the query failed. The final line of PHP will inform us as to how many records teh query retrieved.
71
+
The first block of PHP will create and execute an SQL statement. If this query is successful then inside the `$result` variable will be a list of links. The next block of code will display an error message if the query failed. The final line of PHP will inform us as to how many records the query retrieved.
72
+
73
+
> [More information on PHP and `mysqli_query()`](https://www.php.net/manual/en/mysqli.query.php)
70
74
71
75
4. After the query has executed successfully, add this PHP:
72
76
@@ -91,6 +95,8 @@ while ($record = mysqli_fetch_assoc($result))
91
95
92
96
The above code will loop through each record and display the link. From here the link information will need to be formatted using HTML just like the [php-for-while](https://github.com/codeadamca/php-for-while) and [php-if-switch](https://github.com/codeadamca/php-if-switch) examples.
93
97
98
+
> [More information on PHP and `mysqli_fetch_assoc()`](https://www.php.net/manual/en/mysqli-result.fetch-assoc.php)
99
+
94
100
## Tutorial Requirements:
95
101
96
102
*[Visual Studio Code](https://code.visualstudio.com/) or [Brackets](http://brackets.io/) (or any code editor)
0 commit comments