Php web development

php MySQL web development
Learn Php and develop powerful website that can be use by company to promote, advertise, market and sell their products and service online. The way off doing businesses today is different from the past; the traditional way of doing business is now changing. Products and services today are available online; you can do paperless transaction and pay your bill using a credit card, debit card or transfer of accounts from bank to another bank. There is a demand of web developer today to build websites using Php and MySql database.

Below is a basic tutorial on how to create database in MySql, after that create a table that will be used in storing the data, then html to create user interface and a Php script that will be used to add or store data to database. Let assumes that the database is already created in MySql database and the name of the database is college and it has a table called student with the following field names: accountno, fname, mname, lname, course, major, sex.

Below is the html code and php code that will serve as the interface and instruction set or source code to add or insert data to MySql database. The html code will create a form with text boxes that will be used to enter data to be stored in MySql database such as account number, first name, middle name, last name, course, major and sex. The Php code contains the instruction to store the data coming from form to a variable temporarily then using the conditional statement the code will check if the form is completely fill in, if it is then it will prompt the user to complete the form otherwise if the form is fill in properly, it will insert the data to MySql database using the insert into SQL statement.

The html code of the design interface:

<HTML>
<HEAD>
<TITLE>Student Grade Online</TITLE>
</head>
<body>
<h1>Add Student Records</h1>             
<hr>
 <form action="addstudent.php" method="POST">
<table>
<tr>
<td valign="top"><b><font size="-1">Account Number:</font></b></td>
<td width="705">
<input size="15" maxlenght="15" type="text" name="accountno">
</td>
</tr>
<tr>
<td valign="top"><b><font size="-1">First Name:</font></b></td>
<td>
<input size="30" maxlenght="30" type="text" name="fname">
</td>
</tr>
<tr>
<td valign="top"><b><font size="-1">Middle Name:</font></b></td>
<td>
<input size="5" maxlenght="2" type="text" name="mname">
</td>
</tr>
<tr>
<td valign="top"><b><font size="-1">Last Name:</font></b></td>
<td>
<input size="30" maxlenght="30" type="text" name="lname">
</td>
</tr>
<tr>
<td valign="top"><b><font size="-1">Course:</font></b></td>
<td>
<input size="30" maxlenght="30" type="text" name="course">
</td>
</tr>
<tr>
<td valign="top"><b><font size="-1">Major:</font></b></td>
<td>
<input size="30" maxlenght="30" type="text" name="major">
</td>
</tr>
<tr>
<td valign="top"><b><font size="-1">Sex:</font></b></td>
<td>
<input size="30" maxlenght="30" type="text" name="sex">
</td>
</tr>
<tr>
<td colspan=2>
<p>
<input type="Submit" name="submit" value="Add">
</p>
</td>
</tr>                         
</table>
</form>
</BODY>
</HTML>

The Php code that will be use to add or insert the data to database:

<?php
                // open database conection
                $connection = mysql_connect("localhost","root") or die ("Unable to connect!");

                // select database
                mysql_select_db("grade4c") or die ("Unable to select database!");
               
                $accountno=$_POST['accountno'];
                $fname=$_POST['fname'];
                $mname=$_POST['mname'];
                $lname=$_POST['lname'];
                $course=$_POST['course'];
                $major=$_POST['major'];
                $sex=$_POST['sex'];


                if (trim($_POST['accountno'])==""){
                                echo "Data was not save. Please input acoount no.";
                exit;
        }
               
       if (trim($_POST['fname'])==""){
                                echo "Data was not save. Please input first name.";
                exit;
        }

                                if (trim($_POST['mname'])==""){
                                echo "Data was not save. Please input middle name.";
                exit;
        }
                               
                                if (trim($_POST['lname'])==""){
                                echo "Data was not save. Please input last name.";
                exit;
        }

                                if (trim($_POST['course'])==""){
                                echo "Data was not save. Please input course.";
                exit;
        }

                if (trim($_POST['major'])==""){
                                echo "Data was not save. Please input major.";
                exit;
        }

                if (trim($_POST['sex'])==""){
                                echo "Data was not save. Please sex.";
                exit;
        }


       // generate and execute query
                $query = "INSERT INTO student(accountno,fname,mname,lname,course, major, sex) VALUES('$accountno','$fname','$mname','$lname','$course', '$major', '$sex')";
                $result=mysql_query($query) or die("Error in query: $query. " . mysql_error());
                echo '<font size=-1 color="red">Data was save successfully.</font>';
                //close database connection
                mysql_close($connection);
       

?>