Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $host = "localhost"; // use your real host name
- $username = "roton"; // use your real login user name
- $password = "Roton123"; // use your real login password
- $dbName = "rotonhageton"; // use your real database name
- $con = mysqli_connect( "$host", "$username", "$password", "$dbName" );
- if( !$con ) // == null if creation of connection object failed
- {
- // report the error to the user, then exit program
- die("connection object not created: ".mysqli_error($con));
- }
- if( mysqli_connect_errno() ) // returns false if no error occurred
- {
- // report the error to the user, then exit program
- die("Connect failed: ".mysqli_connect_errno()." : ". mysqli_connect_error());
- }
- $login = "krisu";
- $password = "krisu123";
- if($_POST['loginForm']) {
- if($_POST['password'] == $password && $_POST['login'] == $login) {
- $_SESSION['loggedIn'] = true;
- } else {
- $_SESSION['loggedIn'] = false;
- }
- }
- if($_POST['addBookForm']) {
- $sql = "INSERT INTO 'books' ('book_author', 'book_name', 'price') VALUES (".$_POST['book_author'].", ".$_POST['book_name'].", ".$_POST['book_price'].")";
- if ($con->query($sql) === TRUE) {
- echo "New record created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . $con->error;
- }
- }
- if($_SESSION['loggedIn'] == false) {
- ?>
- <form method="post">
- Login:
- <input type="text" name="login"></input><br>
- Password:
- <input type="password" name="password"></input><br>
- <input type="submit" name="loginForm"></input>
- </form>
- <?php
- } else {
- ?>
- <form method="post">
- Nowa ksiazka:
- <input type="text" name="book_name"></input><br>
- Autor:
- <input type="text" name="book_author"></input><br>
- Cena:
- <input type="number" name="book_price"></input>zł<br>
- <input type="submit" name="addBookForm">
- </form>
- <?php
- if ($result = $con->query("SELECT * FROM 'books'")) {
- while ($row=mysqli_fetch_assoc($result))
- {
- echo "Ksiazka".$row['book_title']."ktorej autor to ".$row['book_author']." kosztuje ".$row['price']."<BR>";
- }
- $result->close();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement