Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [wybieranie z bazy]
- <?php
- require_once "connect.php";
- $polaczenie = @new mysqli($host, $db_user, $db_password, $db_name);
- for($i=1; $i<=4; $i++)
- {
- $zapytanie = mysqli_query($polaczenie,"SELECT id, Nazwa_produktu, Cena_produktu FROM produkty_ostrykebsik WHERE id='$i'");
- $wiersz = $zapytanie->fetch_assoc();
- $_SESSION['id_p'][$i] = $wiersz['id'];
- $_SESSION['nazwa'][$i] = $wiersz['Nazwa_produktu'];
- $_SESSION['cena'][$i] = $wiersz['Cena_produktu'];
- }
- ?>
- [connect1.php]
- <?php
- $host = "localhost";
- $db_user = "root";
- $db_password = "";
- $db_name = "osadnicy";
- ?>
- [index.php]
- <!DOCTYPE HTML>
- <html>
- <head>
- <title> Dodawanie rekordów </title></head>
- <body>
- <form action="connect.php" method="post">
- imię:<br />
- <input type="text" name="imie" /><br />
- nazwisko:<br />
- <input type="text" name="nazwisko" /><br />
- <input type="submit" value="dodaj" />
- </form>
- </body>
- </html>
- [connect.php]
- <?php
- $imie = $_POST['imie'];
- $nazwisko = $_POST['nazwisko'];
- if($imie and $nazwisko) {
- require("connect.php");
- connection();
- $ins = @mysql_query("INSERT INTO test SET imie='$imie', nazwisko='$nazwisko'");
- if($ins) echo "Rekord został dodany poprawnie";
- else echo "Błąd nie udało się dodać nowego rekordu";
- }
- echo "<p>Witaj ".'! [ <a href="table.php">Wyświetl dane z bazy danych!</a> ]</p>';
- echo "<p>Witaj ".'! [ <a href="index.php">Wyświetl dane z bazy danych!</a> ]</p>';
- ?>
- [connection.php]
- <?php
- function connection() {
- $mysql_server = "localhost";
- $mysql_admin = "root";
- $mysql_pass = "";
- $mysql_db = "egz";
- @mysql_connect($mysql_server, $mysql_admin, $mysql_pass)
- or die('Brak połączenia z serwerem MySQL.');
- @mysql_select_db($mysql_db)
- or die('Błąd wyboru bazy danych.');
- }
- ?>
- [table.php]
- <?php
- require("connection.php");
- connection();
- $wynik = mysql_query("SELECT * FROM test")
- or die('Błąd zapytania');
- if(mysql_num_rows($wynik) > 0) {
- echo "<table cellpadding=\"2\" border=1>";
- while($r = mysql_fetch_assoc($wynik)) {
- echo "<tr>";
- echo "<td>".$r['imie']."</td>";
- echo "<td>".$r['nazwisko']."</td>";
- echo "<td>
- <a href=\"index.php?a=del&id={$r['id']}\">DEL</a>
- <a href=\"index.php?a=edit&id={$r['id']}\">EDIT</a>
- </td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- ?>
- [szablon.html]
- <!DOCTYPE HTML>
- <html lang="pl">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <link rel="stylesheet" type="text/css" href="style.css">
- <title></title>
- </head>
- <body>
- <div id="container">
- </div>
- </body>
- </html>
- [style.css]
- body
- {
- margin: 0;
- }
- #container
- {
- width: 1000px;
- height: 1000px;
- margin-left: auto;
- margin-right: auto;
- }
- [tablice asocjacyjne]
- <?php
- echo("<font size='18'><b>". "TABLICE" ."</font></b><br><br>");
- $tablicaA=array(0,1,2,3,4,5);
- for($i=0; $i<=5; $i++)
- {
- print($tablicaA[$i]." ");
- }
- print("<br><br>");
- for($i=0 ; $i<10 ; $i++)
- {
- $tablica[$i]=rand(1,100);
- }
- rsort($tablica);
- for($i=0 ; $i<10 ; $i++)
- {
- print($tablica[$i]." ");
- }
- print("<br><br><b>Tablice asocjacyjne</b><br>");
- $tabliczka = array('j.pol' => '5'
- , 'mat' => '4'
- , 'fiz' => '3'
- , 'wf' => '2'
- , 'pai' => '1');
- print_r($tabliczka);
- print("<br>Sortowanie według argumentów:<br>");
- asort($tabliczka);
- print_r($tabliczka);
- print("<br>Sortowanie według klucza:<br>");
- ksort($tabliczka);
- print_r($tabliczka);
- print("<br><br><br>");
- $panstwa = array('Wielka Brytania' => 'Londyn'
- , 'Stany Zjednoczone' => 'Waszyngton'
- , 'Kanada' => 'Ottawa'
- , 'Australia' => 'Canberra'
- , 'Chiny' => 'Pekin'
- , 'Polska' => 'Warszawa'
- , 'Hiszpania' => 'Madryt'
- , 'Niemcy' => 'Berlin'
- , 'Izrael' => 'Jerozolima');
- print_r($panstwa);
- print("<br><br>");
- asort($panstwa);
- print_r($panstwa);
- print("<br><br>");
- ksort($panstwa);
- print_r($panstwa);
- ?>
- [tablice]
- <?php
- echo("<font size='18'><b>". "TABLICE" ."</font></b><br><br>");
- $tablicaA=array(0,1,2,3,4,5);
- for($i=0; $i<=5; $i++)
- {
- print($tablicaA[$i]." ");
- }
- print("<br><br>");
- for($i=0 ; $i<10 ; $i++)
- {
- $tablica[$i]=rand(1,100);
- }
- rsort($tablica);
- for($i=0 ; $i<10 ; $i++)
- {
- print($tablica[$i]." ");
- }
- ?>
- [obsluga plikow]
- <?php
- echo("<br><font size='18'><b>". "OBSŁUGA PLIKÓW" ."</font></b><br><br>");
- $plik = fopen("zadanie.txt","w+");
- fputs($plik, "Temat: Obsługa plików w obiektowym języku programowania PHP");
- fclose($plik);
- $plik= fopen("zadanie.txt","r");
- while($wiersz = fgets($plik, 1024))
- {
- print($wiersz);
- }
- fclose($plik);
- print("<br><br>");
- $imie = fopen("dane.txt","w+");
- fputs($imie, "Łukasz Świdziniewski");
- fclose($imie);
- $imie= fopen("dane.txt","r");
- while($wiersz2 = fgets($imie, 1024))
- {
- print($wiersz2);
- }
- fclose($imie);
- ?>
- [formularz.html]
- <html>
- <head>
- <title>Formularze</title>
- </head>
- <body>
- <script type="text/javascript">
- function formularz(formularz)
- {
- if (formularz.login.value=="")
- {
- alert("Nie uzupełniłeś loginu.");
- }
- else if(formularz.haslo.value=="")
- {
- alert("Nie uzupełniłeś hasła.");
- }
- else if(formularz.imie.value=="")
- {
- alert("Nie uzupełniłeś imienia.");
- }
- else if(formularz.nazwisko.value=="")
- {
- alert("Nie uzupełniłeś nazwiska.");
- }
- else if(formularz.plec.value=="")
- {
- alert("Nie uzupełniłeś płci.");
- }
- else
- {
- alert("Dziękujemy za wypełnienie formularza.");
- }
- }
- function formularz2(formularz2)
- {
- alert("Wyczyszczono uzupełnione dane.");
- }
- </script>
- <form>
- Login:
- <input name="login" maxlength="10"><br><br></input>
- Hasło:
- <input type="password" name="haslo"><br><br></input>
- Imię:
- <select name="imie">
- <option>Łukasz</option>
- <option>Andrzej</option>
- <option>Piotr</option>
- <option>Maciej</option>
- </select>
- <br><br>
- Nazwisko:
- <input type="text" name="nazwisko" value="Kowalski"></input>
- <br><br>
- Płeć: <br>
- <input type="radio" name="plec">Mężczyzna<br></input>
- <input type="radio" name="plec">Kobieta<br></input>
- <br><br>
- Hobby:<br>
- <input type="checkbox">Książki<br></input>
- <input type="checkbox">Sport<br></input>
- <input type="checkbox">Nauka<br></input>
- <input type="checkbox">Gry<br></input>
- <br><br>
- Opinia<br>
- <textarea name="area" cols="30" rows="5"></textarea><br><br>
- <input type="button" onClick="formularz(this.form)" value="Wyślij"></input>
- <input type="reset" onClick="formularz2(this.form)" value="Wyczyść"></input>
- </form>
- </body>
- </html>
- [obliczenia js]
- <body>
- <script type="text/javascript">
- function licz(formularz) {
- if (formularz.a.value=="" | formularz.b.value=="")
- alert ("Wprowadz dane");
- else {
- a=formularz.a.value;
- b=formularz.b.value;
- formularz.p.value=a*b;
- formularz.o.value=2*a+2*b;
- }
- }
- </script>
- <form name="formularz1" action="">
- Podaj bok a: <input type="text" name="a"><br>
- Podaj bok b: <input type="text" name="b"><br>
- <input type="button" value="Oblicz" onClick="licz(this.form)"><br>
- Wynik:<br>
- Pole prostokąta: <input type="text" name="p"><br>
- Obwód prostokąta: <input type="text" name="o"<br>
- </form>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement