예제 #1
0
//echo "Are we online: " . $are_we_online; // prints 0 or 1.
// Let us run a query.
$sql = $db->query("SELECT * FROM {admins}");
// The variable $sql will now hold the data returned from the database, we can now work with it.
// Does it have rows ?
/*$hasRows = $db->hasRows($sql);
  echo "Does it have rows: " . $hasRows; // prints 0 or 1 (true or false).
  
  // How many rows does it have.
  $countRows = $db->countRows($sql);
  echo "How many rows: " . $countRows; // returns the number of rows.*/
// We can get the data from the fetch_assoc function.
//$result = $db->fetchAssoc($sql);
// We can get the data from the fetch_array function.
$result = $db->fetchArray($sql);
//We can even print out the latest used query:
//echo $db->lastQuery();
$dbusername = $result['username'];
$dbpwd = $result['password'];
if ($entrduname == $dbusername && $entrdpwd == $dbpwd) {
    $_SESSION["username"] = $dbusername;
    $_SESSION["password"] = $dbpwd;
    $url = 'sports.php';
    echo '<META HTTP-EQUIV=REFRESH CONTENT="0; ' . $url . '">';
} else {
    $url = 'index.php';
    echo '<META HTTP-EQUIV=REFRESH CONTENT="0; ' . $url . '">';
}
// As a last thing, close the connection.
$db->closeConnection();
예제 #2
0
 public function addSport($arr)
 {
     $lname = $arr["loc_name"];
     $ltdd = $arr["lattd"];
     $lngtdd = $arr["longtd"];
     $config = new config("localhost", "root", "", "play_a_sport_db", "", "mysqli");
     $db = new db($config);
     $db->openConnection();
     $result = $db->addNewSportRecord($lname, $ltdd, $lngtdd);
     $db->closeConnection();
     if ($result === TRUE) {
         $url = 'sports.php';
         echo '<META HTTP-EQUIV=REFRESH CONTENT="0; ' . $url . '">';
     } else {
         $_SESSION["inlocname"] = $lname;
         $_SESSION["inltdd"] = $ltdd;
         $_SESSION["inlngtdd"] = $lngtdd;
         $url = 'sport_new.php';
         echo '<META HTTP-EQUIV=REFRESH CONTENT="0; ' . $url . '">';
     }
 }