$contents = fread($handle, filesize($filename)); $names = []; $location = []; $date = []; $area = []; $park = explode(PHP_EOL, $contents); print_r($park); foreach ($park as $key => $value) { $newpark = explode(',', $value); $key1 = "park"; $key2 = "location"; $key3 = "date"; $key4 = "area"; $newpark[$key1] = $newpark[0]; $newpark[$key2] = $newpark[1]; $newpark[$key3] = $newpark[2]; $newpark[$key4] = trim($newpark[3]); echo count($newpark) / 2; for ($i = 0; $i < count($newpark) - 1; $i++) { unset($newpark[$i]); } print_r($newpark); $park[$key] = $newpark; } array_pop($park); $dbc = new Mysql("parks_db", "national_parks", 1); $dbc->newTable(); for ($i = 0; $i < count($park); $i++) { $dbc->openAndAdd("{$park[$i]["park"]}", "{$park[$i]["location"]}", "{$park[$i]["date"]}", "{$park[$i]["area"]}"); $dbc->littleBobbyTables("name", "location", "date_established", "area_in_acres"); }
<?php require "database.php"; $names = ["Acadia", "Arches", "Badlands", "Big Bend", "Biscayne", "Bryce Canyon", "Carlsbad"]; $location = ["Maine", "Utah", "South Dakota", "Texas", "Florida", "Utah", "New Mexico"]; $date = ["1919-02-26", "1929-04-12", "1978-11-10", "1944-06-12", "1980-06-28", "1928-02-25", "1930-05-14"]; $area = [47389.67, 76518.98, 242755.94, 801163.21, 172924.07, 35835.08, 46766.45]; $dbc = new Mysql("parks_db", "national_parks", 2); print_r($names); $dbc->deleteTableInfo(); $dbc->newTable(); for ($i = 0; $i < count($names); $i++) { $dbc->openAndAdd($names[$i], $location[$i], $date[$i], $area[$i]); $dbc->reallyAdd("name", "location", "date_established", "area_in_acres"); }
$array["posted"] = date('F jS\\, Y h:i:s'); $array["textbody"] = htmlspecialchars($_POST["textbody"]); $array["image"] = $img; return $array; } $jsonarray = jsonArray($imgFile); print_r($jsonarray); $mysql = new Mysql(); $json = new Json("test"); if ($securimage->check($_POST['captcha_code']) == false) { echo "Ding dong, you're wrong!"; echo "Go <a href='javascript:history.go(-1)'>back</a> and try again."; exit; } else { move_uploaded_file($_FILES["imgupload"]["tmp_name"], $imgFile); $mysql->openAndAdd($jsonarray["title"], $jsonarray["posted"], $jsonarray["textbody"], $jsonarray["image"]); $mysql->reallyAdd(); $awesome = true; } if ($awesome) { echo "You did it!"; $uploadsuccess = true; } else { echo "OOPS. There was an error... (._.')"; } if ($uploadsuccess == true) { // header("Location: /testblog.php"); echo "success"; } ?> <!DOCTYPE html>
<?php require_once "database.php"; require_once "../Input.php"; $dbc = new Mysql("parks_db", "national_parks", 0); var_dump($_POST); try { $dbc->openAndAdd(Input::getString("parkname"), Input::getString("state"), Input::getString("established"), Input::getString("size")); } catch (Exception $e) { echo "Oops! You broke the internet... ;_; " . $e->getMessage() . PHP_EOL; } try { $dbc->littleBobbyTables("name", "location", "date_established", "area_in_acres"); } catch (Exception $e) { echo "Uh oh! There's a problem with uploading to our database! o_o'" . $e->getMessage() . PHP_EOL; } echo "I'm still running though!"; header("Location: /national_parks.php");