Guest User

Untitled

a guest
Sep 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.91 KB | None | 0 0
  1. <?php
  2. require("settings/config.php");
  3. require("settings/dbconnect.php");
  4.  
  5. if(isset($_POST["+2ale"])) {
  6.    $rs = $con->query("SELECT `Name`, `LifeExpectancy` FROM `world_Country` WHERE `Continent` = 'Africa' AND `GovernmentForm` = 'Republic' ORDER BY `Name` DESC");
  7.    
  8.     //update rows with +2
  9.     while($row = $rs->fetch_object()) {
  10.         $lifeexp = $row->LifeExpectancy;
  11.         $newlife = $lifeexp + 2;
  12.         $name = $row->Name;
  13.        
  14.         $con->query("UPDATE `world_Country` SET `LifeExpectancy` = '$newlife' WHERE `Name` = '$name'") or die("unable");
  15.     }
  16. } elseif (isset($_POST["-2ale"])) {
  17.     $rs = $con->query("SELECT `Name`, `LifeExpectancy` FROM `world_Country` WHERE `Continent` = 'Africa' AND `GovernmentForm` = 'Republic' ORDER BY `Name` DESC");
  18.    
  19.     //update rows with -2
  20.     while($row = $rs->fetch_object()) {
  21.         $lifeexp = $row->LifeExpectancy;
  22.         $newlife = $lifeexp - 2;
  23.         $name = $row->Name;
  24.        
  25.         $con->query("UPDATE `world_Country` SET `LifeExpectancy` = '$newlife' WHERE `Name` = '$name'") or die("unable");
  26.     }
  27. }
  28.  
  29.  
  30. ?>
  31. <!DOCTYPE html>
  32. <html>
  33.     <head>
  34.         <link rel="stylesheet" type="text/css" href="style/main.css" media="screen" />
  35.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  36.         <title>Home</title>
  37.     </head>
  38.     <body>
  39.         <h1 class="top">MySQLi
  40.             <?php require("includes/menu.php") ?>
  41.         </h1>
  42.         <div class="wrap">
  43.         <form action="" method="POST">
  44.             <input type="submit" value="+2 years life excpectancy in african republics" name="+2ale"  class="submitbtn"/> -
  45.             <input type="submit" value="-2 years life expectancy in african republics" name="-2ale" class="submitbtn" />
  46.         </form>
  47.             <h2>New Results :</h2>
  48.             <table>
  49.                 <th>Name</th>
  50.                 <th>New life expectancy</th>
  51.             <?php
  52.                 if(isset($_POST["+2ale"])) {
  53.                     $rs = $con->query("SELECT `Name`, `LifeExpectancy` FROM `world_Country` WHERE `Continent` = 'Africa' AND `GovernmentForm` = 'Republic' ORDER BY `Name` DESC");
  54.                     while(list($name, $life) = $rs->fetch_row()) {
  55.                         echo "<tr>";
  56.                         echo "<td>$name</td>" . "<td>$life</td>";
  57.                         echo "</tr>";
  58.                     }
  59.                 } elseif(isset($_POST["-2ale"])) {
  60.                     $rs = $con->query("SELECT `Name`, `LifeExpectancy` FROM `world_Country` WHERE `Continent` = 'Africa' AND `GovernmentForm` = 'Republic' ORDER BY `Name` DESC");
  61.                      while(list($name, $life) = $rs->fetch_row()) {
  62.                         echo "<tr>";
  63.                         echo "<td>$name</td>" . "<td>$life</td>";
  64.                         echo "</tr>";
  65.                     }
  66.                 }
  67.             ?>
  68.             </table>
  69.         </div>
  70.     </body>
  71. </html>
Add Comment
Please, Sign In to add comment