Search This Blog

  • ()
  • ()
Show more

Lidhja e PHP me MySQL

Lidhja e PHP me MySQL Ushtrim 1: Ndertoni duke perdorur php dhe mysql nje sistem qe simulon menaxhimin e studenteve.Krijoni nje database tes...

Lidhja e PHP me MySQL













Ushtrim 1:


Ndertoni duke perdorur php dhe mysql nje sistem qe simulon menaxhimin e studenteve.Krijoni nje database test dhe ne te nje tabele studente qe mban te dhena si emrin,mbiemrin,dhe degen per cdo studente.


Ndertoni nje nderfaqe ne php qe shton studente te rinj, dhe nje nderfaqe qe menaxhon studentet(afishon,modifikon dhe fshin).





Database

 

-- phpMyAdmin SQL Dump

-- version 3.2.0.1

-- http://www.phpmyadmin.net

--

-- Host: localhost

-- Generation Time: Feb 11, 2013 at 10:13 AM

-- Server version: 5.1.36

-- PHP Version: 5.3.0

 

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

 

--

-- Database: `test`

--

 

-- --------------------------------------------------------

 

--

-- Table structure for table `studente`

--

 

CREATE TABLE IF NOT EXISTS `studente` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `emri` varchar(20) NOT NULL,

  `mbiemri` varchar(30) NOT NULL,

  `dega` varchar(100) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;

 

--

-- Dumping data for table `studente`

--

 

INSERT INTO `studente` (`id`, `emri`, `mbiemri`, `dega`) VALUES

(11, 'John', 'Smith', 'Computer Sciences'),

(12, 'Tom', 'Davolio', 'Bussines Administration'),

(13, 'Nick', 'Fuller', 'Finance'),

(14, 'Robert', 'King', 'Chemistry'),

(15, 'Laura', 'Callahan', 'Biology'),

(16, 'Loren', 'Dodsworth', 'Mathematics ');









index.php

 

<!DOCTYPE html>

<html>

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>Shto Studente</title>

    </head>

    <body>

        <form action="addStudent.php" method="POST">

            <table>

                <tr><td>   Emri : </td> <td><input type="text" id="emri" name="emri"/></td></tr>

                <tr><td>   Mbiemri : </td> <td><input type="text" id="mbiemri" name="mbiemri"/></td></tr>

                <tr><td>   Dega : </td> <td><input type="text" id="dega" name="dega"/></td></tr>

                <tr><td colspan="2"> <input type="submit" value="Shto Student" id="add" name="add" /></td></tr>

 

            </table>

        </form>

    </body>

</html>









addStudent.php

 

<?php

    if(isset($_POST["add"])){

        $emri=$_POST["emri"];

        $mbiemri=$_POST["mbiemri"];

        $dega=$_POST["dega"];

 

    $conn = mysql_connect("localhost","root","") or die("Could not establish connection");

 

    mysql_select_db("test") or die("Database not found");

 

    $query="INSERT INTO studente(emri,mbiemri,dega) VALUES ('".$emri."', '".$mbiemri."', '".$dega."');";

    $result = mysql_query($query);

    if($result){

        header("Location: listStudents.php");

    }else

    {

        echo "User could not be added";

    }

 mysql_close($conn);

}

?>









listStudent.php

 

<div align="center"><b><i><a href="index.php">Shto Studente</a></i></b></div>

<br/>

<?php

 

    $conn = mysql_connect("localhost","root","") or die("Could not establish connection");

    

    mysql_select_db("test") or die("Database not found");

    

    $query="SELECT * FROM studente;";

    $result = mysql_query($query);

    echo"<table border='1' align='center'>";

     echo "<tr align='center'>

                <td><b> NR.</b></td>

                <td><b>Emri</b></td>

                <td><b>Mbiemri</b></td>

                <td><b>Dega</b></td>

                 <td><b>Veprime</b></td>

          </tr>";

     $i=0;

    while($row=  mysql_fetch_array($result)){

        echo "<tr align='center'>

                <td><i>".++$i.".</i></td>

                <td><i> ".$row[1]." </i></td>

                <td><i> ".$row[2]." </i></td>

                <td><i> ".$row[3]." </i></td>

                <td><b> [ <a href='deleteStudent.php?id=".$row[0]."'>Fshi</a> ] |

                   [ <a href='editStudent.php?id=".$row[0]."'>Modifiko</a> ] </b></td>

                 

              </tr>";

    }

    echo"</table>";

    

    mysql_close($conn);

?>








deleteStudent.php

 

<?php

    $id=$_REQUEST["id"];

 $conn = mysql_connect("localhost","root","") or die("Could not establish connection");

    

    mysql_select_db("test") or die("Database not found");

    

    $query="DELETE FROM studente WHERE id=".$id;

    

    $result = mysql_query($query);

    if($result){

        header("Location: listStudents.php");

    }

    mysql_close($conn);

?>







editStudent.php

 


<?php

 

if(isset($_REQUEST["id"])){

$id=$_REQUEST["id"];

 

 $conn = mysql_connect("localhost","root","") or die("Could not establish connection");

    

    mysql_select_db("test") or die("Database not found");

    

    if(isset($_POST["edit"]))

    {

        $emri=$_POST["emri"];

        $mbiemri=$_POST["mbiemri"];

        $dega=$_POST["dega"];

 

        $query="UPDATE studente SET emri='".$emri."', mbiemri='".$mbiemri."', dega='".$dega."' WHERE id=".$id;

        $result = mysql_query($query);

        if($result) 

         header("Location: listStudents.php");  

        

    }

    $query="SELECT * FROM studente WHERE id=".$id;

    

    $result = mysql_query($query);

    

    @ $row = mysql_fetch_row($result);

    ?>

     <form action="editStudent.php?id=<?php echo $id;?>" method="GET">

            <table>

                <tr><td>   Emri : </td> <td><input type="text" id="emri" name="emri" value="<?php echo $row[1]?>"/></td></tr>

                <tr><td>   Mbiemri : </td> <td><input type="text" id="mbiemri" name="mbiemri"  value="<?php echo $row[2]?>"/></td></tr>

                <tr><td>   Dega : </td> <td><input type="text" id="dega" name="dega"  value="<?php echo $row[3]?>"/></td></tr>

                <tr><td colspan="2"> <input type="submit" value="Modifiko Student" id="edit" name="edit" /></td></tr>

 

            </table>

        </form>

<?php

    mysql_close($conn);

}else

     header("Location: listStudents.php");

?>






Rezultati:

 

 

 

index.php

 



  listStudent.php


 editStudent.php













 deleteStudent.php



 



Ushtrim 2:


 

Duke perdorur bazen e te dhenave Northwind, afishoni ne formen e nje tabele HTML te gjithe detajet e porosive qe ka bere nje klient te cilin duhet ta zgjidhni paraprakisht nga nje dropdown list.

 







index.php

 

<?php

  $conn = mysql_connect("localhost","root","") or die("Could not establish connection");

    

    mysql_select_db("northwind") or die("Database not found");

    $is_set=FALSE;

    $customerID='';

if(isset($_POST["selected"]))

{

    $customerID=$_POST["selected"];

    $is_set= TRUE;

}

    

?>

<script type="text/javascript">

    function selectedCompany(){

        var sel = document.getElementById('companies');

        var selectedCMP=sel.options[sel.selectedIndex].value;

        document.getElementById("selected").value = selectedCMP;

    }

</script>

<form name="frm" action="index.php" method="POST" align="center">

    <?php

      

    $query="SELECT CustomerID,CompanyName FROM customers;";

    $result = mysql_query($query);

    ?>

    <select  id="companies" onchange="selectedCompany()">

        <option value="">Select Company</option>

        <option value="">-----------------------</option>

    <?php

    while ($row = mysql_fetch_array($result)) {

    ?>

        <option value="<?php echo $row["CustomerID"]; ?>" <?php if($is_set && $customerID==$row["CustomerID"]) echo "selected";?>  ><?php echo $row["CompanyName"]; ?></option>

    <?php

    }

    ?>

    </select>

    <input type="hidden" name="selected" id="selected">

    <input type="submit" name="submit" value="Select"/>

</form>

<?php

if($is_set)

{

    $query="SELECT customers.CompanyName, employees.FirstName, employees.LastName, orders.OrderID, order_details.UnitPrice, order_details.Quantity

            FROM orders

            INNER JOIN order_details ON orders.OrderID = order_details.OrderID

            INNER JOIN customers ON orders.CustomerID = customers.CustomerID

            INNER JOIN employees ON orders.EmployeeID = employees.EmployeeID

            WHERE customers.CustomerID =  '".$customerID."'";

    $result = mysql_query($query);

     echo"<table border='1' align='center'>";

     echo "<tr align='center'>

                <td><b> NR.</b></td>

                <td><b>Company Name</b></td>

                <td><b>Employee</b></td>

                <td><b>Order ID</b></td>

                <td><b>Unit Price</b></td>

                <td><b>Quantity</b></td>

          </tr>";

     $i=0;

    while($row=  mysql_fetch_array($result)){

        echo "<tr align='center'>

                <td><i>".++$i.".</i></td>

                <td><i> ".$row[0]." </i></td>

                <td><i> ".$row[1]." ".$row[2]." </i></td>

                <td><i> ".$row[3]." </i></td>

                <td><i> ".$row[4]." </i></td>

                <td><i> ".$row[5]." </i></td>

              </tr>";

    }

    echo"</table>";

}

mysql_close($conn);

?>



Rezultati:















COMMENTS

Name

apple,2,Article,14,At home,13,Author,14,Beauty,1,Biography,2,blackberry,1,Business,6,Cars,5,Celebrity,13,conspiraci,15,Fashion,5,galaxy,1,Gallery,1,Games,11,google,1,Hair,1,Health amp; Fitness,2,Histori,11,Home,169,HOSTING,27,HTML,7,imac,1,Image,1,iphone,1,Itcyber,7,Kuran,31,Lajme,34,Life amp; Love,1,Makeup amp; Skincare,1,mobile,5,monitor,1,Movies,2,News,5,No category,5,Photography,6,PHP,30,Poezi,24,POEZI amp; TEKSTE,2,Post,14,PROGRAMMIM,46,Relationships,1,review,6,samsung,1,Seo,7,Softvare,4,Sport,5,Sports,7,Stars,5,Tag,7,Tags,7,Tech,30,Teknologji,37,THEMES,3,Tutorials,191,Video,47,Videos,4,Vip News,2,Webhosting,67,WordPress,7,World,13,
ltr
item
Cr337: Lidhja e PHP me MySQL
Lidhja e PHP me MySQL
https://sites.google.com/a/ictedu.info/webprogramming/_/rsrc/1360578420019/seminare/18-lidhja-e-php-me-mysql/add.png
Cr337
https://cr337.blogspot.com/2015/04/lidhja-e-php-me-mysql.html
https://cr337.blogspot.com/
http://cr337.blogspot.com/
http://cr337.blogspot.com/2015/04/lidhja-e-php-me-mysql.html
true
5516280490839897951
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy