Hey,

So now that you’ve got the appserv software, try to check your server. Open up google chrome then type localhost/phpmyadmin.

So, this would be your database. Usually when you just downloaded it, the username would be ‘root’ and there won’t be any password. So now let’s make it ASAP. As Simple  As Possible. To learn something new efficiently, you need to have a purpose for learning it. You’re supposed to learn Y to do X. Say for example, I wanna be a soccer player. So, learning while playing soccer would be faster than training to dribble the ball all day long. It’s also like you’re having fun in the process of learning.

Now, your GOAL is to make a database of people in your company.

1. Create a database.

  • On your left side, click the new button
  • Create a database named ‘company’. (Just type in the name and click create.)

2. Create a table

  • Now let’s create a table named ‘staff’ with the number of columns 2. Click go.
  • For the two columns, name one of it “Name” which is for the name of staff and another one name it “StaffID”. For  the “Name” column, select VARCHAR for type and length 30; while for the“StaffID” select INT for the type while the length is 4. Now just click SAVE.

I know the configure looks complicated but just learn what you really need and things will get easy.

Now, the setup is finished. But what is it missing?

Of course, data. So, the first step that I would like you to learn is INSERT.

You will be inserting the data of the staff inside your company database.

Now, we have two columns, “Name” & “StaffID”.

So, how about we insert the name as ‘Jake’ while the StaffID as ‘1234’.

Pay close attention.

This is the code.

______________________________________________________________

<!DOCTYPE html>
<body>

<?php

$conn = mysqli_connect(“localhost”,”root”,””,”company”);

$insert = “INSERT INTO staff ( Name , StaffID )
VALUES ( ‘Jake’ , ‘1234’)”;

if(mysqli_query($conn,$insert))
{
echo “Successful”;
}
else
{
echo “Unsuccessful” . mysqli_error($conn);
}

?>

</body>
</html>

_______________________________________________________________

Explanation

 

1. I opened HTML and PHP (it’s the unbolded and unitalized text) You need to write this so that the computer understands it’s html and php language.

2. $ This dollar sign is a variable name. You can change it to any name.

 3. mysqli_connect(“localhost”,”root”,””,”company”) This is the syntax to connect with the database. localhost is your server name—root is your username—and this space is for password—company is your database name.

4. [  ; ] this sign is to end the php statement.

5.  “INSERT INTO staff ( Name , StaffID )
VALUES ( ‘Jake’ , ‘1234’)”  Now this is the insert syntax. Make sure it starts and ends with “___” and the values should be in ‘__’  .

6. if(mysqli_query($conn,$insert))
{
echo “Successful”;
}
else
{
echo “Unsuccessful” . mysqli_error($conn);
}

This is an if else statement to check whether it’s working or not. If it’s not working, then it’ll tell you what’s wrong.

7. I closed back the HTML and PHP

To try it out, open chrome.

In the url, type localhost/insert.php

 

Now truthfully this isn’t the best practice but it should give you an idea. I know you might not understand, but that’s also how I started out. So, keep on practicing this INSERT until you really master it. Let’s minimize what you learn about SQL and maximize the time you play with it. Go 1 cm width and 1km deep. That’s the way.

~~For any questions, mail me at imdad@zeroprogrammer.com~~

~~Posts come out every day. Stay tuned~~

~~Do leave your comments~~