+ All Categories
Home > Documents > Objectives Create a database using Mysql Create a tables and insert data on them Create a...

Objectives Create a database using Mysql Create a tables and insert data on them Create a...

Date post: 19-Jan-2016
Category:
Upload: garey-dorsey
View: 221 times
Download: 1 times
Share this document with a friend
22
Objectives Create a database using Mysql Create a tables and insert data on them Create a relationship between tables Create a user Export your database to a text file Print & echo variables Arrays Using different types of loops PHP Forms & field validation Insert a record to mysql database using php form Update a record in mysql database using php file Update a record in mysql database using php form Select everything from mysql database table
Transcript
Page 1: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

Objectives

Create a database using Mysql

Create a tables and insert data on them

Create a relationship between tables

Create a user

Export your database to a text file

Print & echo variables

Arrays

Using different types of loops

PHP Forms & field validation

Insert a record to mysql database using php form

Update a record in mysql database using php file

Update a record in mysql database using php form

Select everything from mysql database table

Page 2: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

Activity Outcomes■ The student should know how to Create a database using Mysql in phpmyadmin

■ The student should know how to Create tables and insert data on them

■ The student should know how to Create relations between tables

■ The student should know how to Export your database to a text file

■ The student should know how to print in php

■ The student should know how to use & manipulate arrays in php

■ The student should know how to use loops in php

■ The student should know how to use form and field validation in php

■ The student should know how to Insert a record to mysql database using php form

■ The student should know how to Update a record in mysql database using php file

■ The student should know how to Update a record in mysql database using php form

■ The student should know how to Select everything from mysql database table

Page 3: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

PHPADMIN TABLE

Page 4: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

السيرفر: تشغيل أوال

العنوان: وكتابة للمتصفح الذهاب ثانيا/ http://localhost/phpmyadminالتالي:

Page 5: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

Create a database using Mysql Run the wamp server Open the web browser and write on the address bar http://localhost . The wamp web page will open go to phpmyadmin Create a new database called AZcompany

Page 6: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

Create an Employees table and insert data on it

اسم كتابهوتحديد الجدول

العواميد عدد☺

Page 7: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

الجدول وأعمدة االسم تحدي بعدقاعده في الجدول يضاف

ولتعبئه . الشكل في كما البياناتالجدول أدوات من البيانات

»»ادخال

ويتم االدخال صفحه تظهر بعدهاالبيانات ادخال

Page 8: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

Field name TypeEmp-Id Varchar(20)first-name Varchar(100)last-name Varchar(100)Age Int

1) Create a table called Employees containing 4 fields as follows:

Emp-Id (primary key) first-name Last-name Age

10 Ahmad Ali 30

20 Mohammad Saeed 45

30 Sameer Saleh 35

2)Insert the following data in the Employees table

Page 9: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

1)Now create 2 more tables:

- Department table (Primary-Key(Dept-Id), name)

- Emp-Info table (Primary-Key (Emp-Id, Dept-Id), startDate)

Dept-Id name

101 Accounting

102 Sales

103 Finance

104 Marketing

Fill the Department table with the following data:

Page 10: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

Create a user

Create a user called admin1 and give it all the privileges

Export your data base to a text file

1. Select your data base

2. Export the data base as SQl format and copy the statements to a text file name mydb.sql

Page 11: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

privilege امتيازات /منصالحياته وتحديد مستخدم اضافه تتم

إلخراج تصدير أداة استخدام يتمحذف ثم ومن الجهاز الى البياناتواعادة تصديره تم الذي الجدول

استيراد االداة من استيراده

Page 12: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

PHP

Page 13: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

مجلد في الصلب القرص في بالشكل الظاهر باالمتداد حفظه يجبphp السيرفر ملف عرض أو تشغيل 123 ليتم

Page 14: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

<html><?php $name = "Ahmad"; // declaration and initialization?> <head> <title>Simple PHP document</title> </head> <body style = "font-size: 2em"> <p> <strong> <!-- print variable name’s value -->

<?php echo "Using echo to write this sentence, and print to write the name in red <br/><br/>"; ?> Welcome to PHP, <span style= 'color: red'><?php print( "$name" ); ?>!<span/> </strong> </p> </body></html>

Print & Echo variable In PHP there are two basic ways to get output: echo and print.1. Open the notepad 2. Write the following code 3. save the file as welcome.php in the wamp\www directory 4. open the browser write the following in the address bar (http://localhost/welcome.php)

Page 15: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

<html> <head> <title>Array manipulation</title> </head> <body> <?php$brush_price = 5;echo "<table border=\"1\" align=\"center\">"; echo "<tr><th>Quantity</th>"; echo "<th>Price</th></tr>"; for ( $counter = 10; $counter <= 100; $counter += 10) { echo "<tr><td>"; echo $counter; echo "</td><td>"; echo $brush_price * $counter; echo "</td></tr>"; } echo "</table>"; ?> </body></html>

Arrays Different ways of declaration and using loops for manipulation:

Page 16: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

Using different types of loops with php:

For loop with php While loop with php

Do..while loop with php Foreach loop with php

Page 17: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

<html><body><form action="welcome.php" method="post"><p> Name : <input type="text" name="name"><br></p><p> E-mail: <input type="text" name="email"><br></p> <input type="submit"></form></body></html>

<html><body>Welcome <?php echo $_POST["name"]; ?><br>Your email address is: <?php echo $_POST["email"]; ?></body></html>

PHP FormsFirst we create an html file that contains a form, the action = a php file:

-Now we create the welcome.php file as follows:

Page 18: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

PHP WITH DATABASE

Page 19: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

<html>

<body>

<form action="insert.php" method="post">

Emp-Id: <input type="text" name="id">

First-name: <input type="text" name="firstname">

Last-name: <input type="text" name="lastname">

Age: <input type="text" name="age">

<input type="submit">

</form>

</body>

</html>

Insert into mysql databaseWe want to make a connection between a form and mysql database, so we can insert the values from the form directly into database.

1. First , create an html form and save the file as insertform.html

Page 20: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

2. Second, create a php file and save it as insert.php as the following:

<?php  $con= mysqli_connect("localhost","root","","AZcompany"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO Employees VALUES ('$_POST[id]','$_POST[firstname]','$_POST[lastname]','$_POST[age]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con);?>

Page 21: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

<?php$con=mysqli_connect("localhost","root","","AZcompany");if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"UPDATE Employees SET Age=36 WHERE Emp_Id='10' "); mysqli_close($con);?>

Update a record in mysql database:

Create a php file to update the record directly with known values:

Page 22: Objectives  Create a database using Mysql  Create a tables and insert data on them  Create a relationship between tables  Create a user  Export your.

CONNECTION BETWEEN PHP FORM “SELF

STUDY”


Recommended