Jump to content

Dawid

New Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by Dawid

  1. Could you show me how? Because I guess I didn't understand 😕
  2. Someone can help with this problem? Error: "Fatal error: Uncaught Error: Call to a member function query() on null in /profiles/d/d4/d4v/d4vez/listazakupow.cba.pl/pages/config.php:16 Stack trace: #0 /profiles/d/d4/d4v/d4vez/listazakupow.cba.pl/index.php(18): listaZakupow->usun('6') #1 {main} thrown in /profiles/d/d4/d4v/d4vez/listazakupow.cba.pl/pages/config.php on line 16" index.php <!doctype html> <head> <meta charset="utf-8" /> <title>Lista Zakupów</title> </head> <body> <?php require_once 'pages/config.php'; $lz = new listaZakupow; if(isset($_GET['akcja'])){ switch($_GET['akcja']){ case 'dodaj': $lz->dodaj($_POST['towar']); break; case 'usun': $lz->usun($_GET['id']); break; case 'zmien': $lz->zmienStan($_GET['id']); break; } } $sql = 'SELECT * FROM zakupy'; $result = mysqli_query($link,$sql); if(mysqli_num_rows($result) == 0){ echo 'Nie masz jeszcze dodanego żadnego przedmiotu do kupienia'; } else{ echo 'Twoja lista zakupów:'; while($row = mysqli_fetch_assoc($result)){ $towarid = $row['id']; $towar = $row['towar']; $stan = $row['stan']; echo '<ul>'; if($stan=='T'){ $kupione = 'x'; } else{ $kupione = ' '; } echo '<li>'.$towar.' <a href="index.php?akcja=zmien&id='.$towarid.'">['.$kupione.']</a> <a href="index.php?akcja=usun&id='.$towarid.'">usuń</a></li>'; echo '</ul>'; } } ?> <form action="index.php?akcja=dodaj" method="post"> Towar: <input type="text" name="towar" /> <input type="submit" value="Dodaj" /> </body> </html> config.php <?php $link = new mysqli('localhost,'name','password','database'); if ($link -> connect_errno) { echo 'Nie udało się połączyć z MySQL: ' . $mysqli -> connect_error; exit(); } class listaZakupow{ function dodaj($nazwa){ $link->query('INSERT INTO zakupy VALUES(null,\''.mysqli_real_escape_string($nazwa,$link).'\',\'N\');'); header("location: index.php"); } function usun($id){ $link->query('DELETE FROM zakupy WHERE id='.intval($id).' limit 1'); header("location: index.php"); } function zmienStan($id){ $akt = mysqli_fetch_assoc($link->query('SELECT stan FROM zakupy WHERE id='.intval($id).' limit 1')); if($akt['stan']=='T'){ $nw = 'N'; } else{ $nw = 'T'; } mysqli_query('UPDATE zakupy SET stan=\''.$nw.'\' where id='.intval($id).' limit 1'); header("location: index.php"); } } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.