Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $mysqli = new mysqli("localhost", "root", "", "demo");
- // Check connection
- if($mysqli === false){
- die("ERROR: Could not connect. " . $mysqli->connect_error);
- }
- $first_name = $mysqli->real_escape_string($_REQUEST['first_name']);
- $last_name = $mysqli->real_escape_string($_REQUEST['last_name']);
- $sql = "INSERT INTO Persons (first_name, last_name) VALUES ('$first_name', '$last_name')";
- if($mysqli->query($sql) === true){
- echo "Saved! <br/> <a href=index.php> Back </a> ";
- } else{
- echo "ERROR: Could not able to execute $sql. " . $mysqli->error;
- }
- $sql = "SELECT * FROM Persons";
- if($result = $mysqli->query($sql)){
- if($result->num_rows > 0){
- echo "<table>";
- echo "<tr>";
- echo "<th>Imie</th>";
- echo "<th>Nazwisko</th>";
- echo "</tr>";
- while($row = $result->fetch_array()){
- echo "<tr>";
- echo "<td>" . $row['id'] . "</td>";
- echo "<td>" . $row['first_name'] . "</td>";
- echo "<td>" . $row['last_name'] . "</td>";
- echo "<td><input type='submit' id='".$row['id']."' value='delete' name='delete'></td>";
- echo "</tr>";
- }
- echo "</table>";
- // Free result set
- $result->free();
- } else{
- echo "No records matching your query were found.";
- }
- } else{
- echo "ERROR: Could not able to execute $sql. " . $mysqli->error;
- }
- // Check connection
- if($mysqli === false){
- die("ERROR: Could not connect. " . $mysqli->connect_error);
- }
- if(isset($_GET['delete'])){
- $deleted = $_GET['id'];
- $new ="DELETE FROM Persons WHERE id = $deleted;";
- $dbh->query($new);
- }
- // Close connection
- $mysqli->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement