• Save
Web Application PHP and MySQL Database
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Web Application PHP and MySQL Database

on

  • 1,003 views

 

Statistics

Views

Total Views
1,003
Views on SlideShare
1,003
Embed Views
0

Actions

Likes
0
Downloads
14
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Web Application PHP and MySQL Database Document Transcript

  • 1. Web Database ApplicationsPHP and MYSQL Database Web ApplicationBySunny Okoro
  • 2. ContentsIntroduction ..................................................................................................................................................2Development Tools.......................................................................................................................................2Student Application System..........................................................................................................................3Student Application System Codes...............................................................................................................7Student Application System 2.....................................................................................................................10Student Application System 2 Code............................................................................................................11Student Application System 3.....................................................................................................................13Student Application System Code 3............................................................................................................14
  • 3. IntroductionThis documents contains few web applications written in PHP and HTML scripting languagethat would allow a user to interact with a MySQL databaseDevelopment ToolsDatabase Platform: MySQLWeb Scripting Languages: PHP and HTMLWeb Server: EASY PHP 5.3.8.1 with Apache
  • 4. Student Application SystemNow insert some records into the database by completing the required information.
  • 5. Verify that the information has been inserted into the database to their corresponding table. Student isthe database and school is the table. To accomplish this task, a query is needed.
  • 6. Student Application System Codes<?php/*****************************************************This display array POST*****************************************************///echo "<pre>";//print_r($_POST);//echo "</pre>";/*****************************************************Create variables with information from array POST*****************************************************/$FirstName = $_POST["FirstName"];$LastName = $_POST["LastName"];$Email=$_POST["Email"];$Gender =$_POST ["Gender"];$Password=$_POST["Password"];$ConfirmPassword=$_POST ["ConfirmPassword"];$StudentYear=$_POST["StudentYear"];$Interest=$_POST["Interest"];$picture = $_POST["picture"];$profile = $_POST["profile"];$Sports = $_POST["Sports"];/*************************************connect to mysql********************************************/$server = "Localhost"; // Server name$user = "root"; // User name$pass = "" ; // password$connect = mysql_connect($server, $user, $pass)or die ("Error: Bad connection" );$sel = mysql_select_db(school) or die("Error: Bad connection");$sql = "INSERT INTO Student (FirstName, LastName, Email, Gender, Password,ConfirmPassword, StudentYear, Interest, picture, profile, Sports)";$sql .= "VALUES ("$FirstName", "$LastName", "$Email","$Gender","$Password", "$ConfirmPassword", "$StudentYear","$Interest", "$picture","$profile", "$Sports" )";$query = mysql_query($sql);$numRows = mysql_affected_rows($connect);if ($numRows == 1)echo"<h1> New student added</h1>";
  • 7. mysql_close($connect);?><HTML><html><body><form method= "post" action="student.php"><h1> New Student </H1><table allign ="center" border="1" bgcolor="green"><tr><td align = "right"> FIRST NAME: </td><td><input type="text" name="FirstName"></td></tr><tr><td align = "right"> LAST NAME: </td><td><input type="text" name="LastName"></td></tr><tr><td align = "right"> Email: </td><td><input type= "text" name="Email"></td></tr><tr><td align = "right"> Gender: </td><td><input type="radio" name="Gender" value="Male">Male <br><input type="radio" name="Gender" value="Female">Female </td></tr><tr><td align = "right"> Password: </td><td><input type= "password" name= "Password"></td></tr><tr><td align = "right"> ConfirmPassword: </td><td><input type= "password" name= "ConfirmPassword"></td></tr>
  • 8. <tr><td align = "right"> Student Year:</td><td><select name = "StudentYear"><option >Freshman </option><option>Sophmore </option><option>Junior </option><option>Senior</option><br></select></td></tr><tr><td align = "right"> Interest:</td><td><textarea name= "Interest"></textarea></td></tr><tr><td align = "right"> Options:</td><td><input type="checkbox" name="picture" value = "Share profile "/>Share my profile<input type="checkbox" name="profile" value = "Show picture"/>Share my picture</td></tr><tr><td align = "right"> Sports:</td><td><select name= "Sports"><option>Football</option><option>Baseball</option><option>Basketball</option><option>Volleyball</option><option>Tennis</option></select></td></tr></table><button type ="submit" value ="Submit" name= "Submit"> Submit<img src="http://farm3.static.flickr.com/2038/1830883816_7e6444f018.jpg" width= "50" height="50"></button><button type ="Reset" value ="Reset" name= "Reset" > Reset<img src="http://www.houstonexpress.net/images/houston2.jpg" width= "50" height="50"><br /></button></form>
  • 9. </body</html><Database>Drop database if exists school;Create database if not exists school;Use school;CREATE TABLE student(StudentID int NOT NULL AUTO_INCREMENT,FirstName char(20) NOT NULL,LastName char(20) NOT NULL,Email varchar(30) NOT NULL,Gender char(6) NOT NULL,Password Varchar(20) NOT NULL,ConfirmPassword Varchar(20) NOT NULL,StudentYear char(11) NOT NULL,Interest Text NOT NULL,Picture char (20) NOT NULL,Profile char(20) NOT NULL,Sports char(42) NOT NULL,PRIMARY KEY(StudentID));Student Application System 2Instead of having the user login in to the database to access the data, the user can open a webapplication which displays the content of the database back to them for security reasons.
  • 10. Student Application System 2 Code<?php//echo "<pre>";//print_r($_POST);//echo "</pre>";/**********************************************connect to mysql********************************************/$server = "Localhost"; // Server name$user = "root"; // User name$pass = "" ; // password/********************************************Display message if connection falied**********************************************/$connect = mysql_connect($server, $user, $pass)or die ("Error: Bad connection" );
  • 11. $select = mysql_select_db("school");if(!$select)exit("Error: Could not select database!");$sql = "SELECT * FROM student";$query = mysql_query($sql);if (mysql_num_rows($query) == 0){echo "No records found";}else{echo "<table align=center border = 1>";echo"<tr>";echo "<td><b>StudentID</td>";echo "<td><b>FirstName</td>";echo "<td><b>LastName</td>";echo "<td><b>Email</td>";echo "<td><b>Gender</td>";echo "<td><b>Password</td>";echo "<td><b>ConfirmPassword<td>";echo "<td><b>StudentYear<b></td>";echo "<td><b>Interest</td>";echo "<td><b>profile</td>";echo "<td><b>picture</td>";echo "<td><b>Sports</td>";echo"</tr>";while($row = mysql_fetch_object($query)){echo"<tr>";echo "<td>".$row->StudentID."</td>";echo "<td>".$row->FirstName."</td>";echo "<td>".$row->LastName."</td>";echo "<td>".$row->Email."</td>";echo "<td>".$row->Gender."</td>";echo "<td>".$row->Password."</td>";echo "<td>".$row->ConfirmPassword."<td>";echo "<td>".$row->StudentYear."</td>";echo "<td>".$row->Interest."</td>";echo "<td>".$row->Profile."</td>";echo "<td>".$row->Picture."</td>";echo "<td>".$row->Sports."</td>";}
  • 12. echo"</tr>";}echo"</table>";mysql_close($connect);?>Student Application System 3The user can use the student identification number to specify the student they want their data todisplayed back instead of using the general query of select * from student by using a web application.
  • 13. Student Application System Code3<student.html><html><title> STUDENT DATA </title><head><h1>STUDENT DATA </h1></head><body><form method= "post" action="table2.php">Student ID<input type = "text" name ="STUDENTID"></input><p><button type ="submit" value ="Submit" name= "Submit"> Submit</button><button type ="Reset" value ="Reset" name= "Reset" > Reset</button>
  • 14. <table2.php file><?php//echo "<pre>";//print_r($_POST);//echo "</pre>";/**********************************************connect to mysql********************************************/$server = "Localhost"; // Server name$user = "root"; // User name$pass = "" ; // password/********************************************Display message if connection falied**********************************************/$connect = mysql_connect($server, $user, $pass)or die ("Error: Bad connection" );$select = mysql_select_db("school");if(!$select)exit("Error: Could not select database!");$sql = "SELECT * FROM student WHERE STUDENTID = STUDENTID";$query = mysql_query($sql);if (mysql_num_rows($query) == 0){echo "No records found";}else{echo "<table align=center border = 1>";echo"<tr>";echo "<td><b>StudentID</td>";echo "<td><b>FirstName</td>";echo "<td><b>LastName</td>";echo "<td><b>Email</td>";echo "<td><b>Gender</td>";echo "<td><b>Password</td>";echo "<td><b>ConfirmPassword<td>";echo "<td><b>StudentYear<b></td>";echo "<td><b>Interest</td>";echo "<td><b>profile</td>";
  • 15. echo "<td><b>picture</td>";echo "<td><b>Sports</td>";echo"</tr>";while($row = mysql_fetch_object($query)){echo"<tr>";echo "<td>".$row->StudentID."</td>";echo "<td>".$row->FirstName."</td>";echo "<td>".$row->LastName."</td>";echo "<td>".$row->Email."</td>";echo "<td>".$row->Gender."</td>";echo "<td>".$row->Password."</td>";echo "<td>".$row->ConfirmPassword."<td>";echo "<td>".$row->StudentYear."</td>";echo "<td>".$row->Interest."</td>";echo "<td>".$row->Profile."</td>";echo "<td>".$row->Picture."</td>";echo "<td>".$row->Sports."</td>";}echo"</tr>";}echo"</table>";mysql_close($connect);?>