Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require("settings/config.php");
- require("settings/dbconnect.php");
- if(isset($_POST["+2ale"])) {
- $rs = $con->query("SELECT `Name`, `LifeExpectancy` FROM `world_Country` WHERE `Continent` = 'Africa' AND `GovernmentForm` = 'Republic' ORDER BY `Name` DESC");
- //update rows with +2
- while($row = $rs->fetch_object()) {
- $lifeexp = $row->LifeExpectancy;
- $newlife = $lifeexp + 2;
- $name = $row->Name;
- $con->query("UPDATE `world_Country` SET `LifeExpectancy` = '$newlife' WHERE `Name` = '$name'") or die("unable");
- }
- } elseif (isset($_POST["-2ale"])) {
- $rs = $con->query("SELECT `Name`, `LifeExpectancy` FROM `world_Country` WHERE `Continent` = 'Africa' AND `GovernmentForm` = 'Republic' ORDER BY `Name` DESC");
- //update rows with -2
- while($row = $rs->fetch_object()) {
- $lifeexp = $row->LifeExpectancy;
- $newlife = $lifeexp - 2;
- $name = $row->Name;
- $con->query("UPDATE `world_Country` SET `LifeExpectancy` = '$newlife' WHERE `Name` = '$name'") or die("unable");
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="style/main.css" media="screen" />
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Home</title>
- </head>
- <body>
- <h1 class="top">MySQLi
- <?php require("includes/menu.php") ?>
- </h1>
- <div class="wrap">
- <form action="" method="POST">
- <input type="submit" value="+2 years life excpectancy in african republics" name="+2ale" class="submitbtn"/> -
- <input type="submit" value="-2 years life expectancy in african republics" name="-2ale" class="submitbtn" />
- </form>
- <h2>New Results :</h2>
- <table>
- <th>Name</th>
- <th>New life expectancy</th>
- <?php
- if(isset($_POST["+2ale"])) {
- $rs = $con->query("SELECT `Name`, `LifeExpectancy` FROM `world_Country` WHERE `Continent` = 'Africa' AND `GovernmentForm` = 'Republic' ORDER BY `Name` DESC");
- while(list($name, $life) = $rs->fetch_row()) {
- echo "<tr>";
- echo "<td>$name</td>" . "<td>$life</td>";
- echo "</tr>";
- }
- } elseif(isset($_POST["-2ale"])) {
- $rs = $con->query("SELECT `Name`, `LifeExpectancy` FROM `world_Country` WHERE `Continent` = 'Africa' AND `GovernmentForm` = 'Republic' ORDER BY `Name` DESC");
- while(list($name, $life) = $rs->fetch_row()) {
- echo "<tr>";
- echo "<td>$name</td>" . "<td>$life</td>";
- echo "</tr>";
- }
- }
- ?>
- </table>
- </div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment