This week:
- write a PHP script that will connect to a MySQL database
- create a SQL query to retrieve information from a table
- create a SQL query to insert data into a table
- write PHP code that outputs query results to a web page
It was very easy to enter information from the tables ready in SQL and to call this information to the web environment. However, the connection that must be made in sending the form prepared in the Web environment to the Sql data is very challenging for me. I’ve been trying to find a link to this for the last 2 days. And I can’t see anything. But I have high belief that I can finally do it 😀
UPDATE…
It was very challenging assignment “Web Project 4: Add User/View User list and Add Department/View Department list” . I made modification yo my USER List. Adding 5 more rows of data to my User table, creating new Table called “Department” was easy to me. I didn’t changed db.php codes.

On the other hand “Modify your web form to connect to and add a SQL insert statement to input the form values and add a new record to the USER table via this form. ” was different story. This was very challenge for me. This was very difficult for me. I read the book and read the codes in it. I figured out what the codes were. But I could not create a new record. During this process, I looked at the book over and over again for 4 days and watched youtube. But there were also deficiencies in the codes on youtube. The last youtube video I found, showed very basic links and codes and adding new user to Sql. In this way, I got the AHA moment. VOILA and I succeeded.
Some important codes :
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’)
——-
$q = “INSERT INTO USER(first_name, last_name, email, password)
VALUES
(‘$first_name’ , ‘$last_name’ , ‘$email’ , ‘$password’)”;
$r = mysqli_query($connection, $q); // Run the query.
if ($r) { // If it ran OK.
——
Questions :
1-Book gave code
SHA2(‘$password’, 512) ==> this code created random password inside Sql database when I created different password in register form so I used only “password”.
2-I added new user into the database but when I deleted them and added another user, I saw user_Id not deleted and now after first 10 user id starts with 50. How can I deleted this empty user_id numbers?