Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <?php
- ini_set("display_errors", 1);
- ini_set("display_startup_errors", 1);
- error_reporting(E_ALL);
- ?>
- <html>
- <head>
- <title>Friends and Family</title>
- </head>
- <body>
- <?php
- // INSERT FUNCTION
- function insert($conn, $a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n)
- {
- $query = "INSERT INTO people values('$a','$b','$c','$d','$e','$f',$g,'$h',$i,$j,'$k','$l','$m','$n',NULL)";
- $result = $conn->query($query);
- if (!$result)
- die("Database access failed: " . $conn->error);
- echo 'success!';
- }
- require_once 'login.php';
- $conn = new mysqli($hn, $un, $pw, $db);
- if ($conn->connect_error)
- die($conn->connect_error);
- //CREATE
- if (isset($_POST['create']))
- {
- $fname = $_POST['fname'];
- $lname = $_POST['lname'];
- $phone = $_POST['phone'];
- $address = $_POST['address'];
- $city = $_POST['city'];
- $state = $_POST['state'];
- $zip = $_POST['zip'];
- $month = $_POST['month'];
- $day = $_POST['day'];
- $year = $_POST['year'];
- $myusername = $_POST['myusername'];
- $mypassword = $_POST['mypassword'];
- $sex = $_POST['sex'];
- $relation = $_POST['relation'];
- echo $fname . '<br>';
- echo $lname . '<br>';
- echo $phone . '<br>';
- echo $address . '<br>';
- echo $city . '<br>';
- echo $state . '<br>';
- echo $zip . '<br>';
- echo $month . '<br>';
- echo $day . '<br>';
- echo $year . '<br>';
- echo $myusername . '<br>';
- echo $mypassword . '<br>';
- echo $sex . '<br>';
- echo $relation . '<br>';
- insert($conn, $fname, $lname, $phone, $address, $city, $state, $zip, $month, $day, $year, $myusername, $mypassword, $sex, $relation);
- }
- //SEARCH
- if (isset($_POST['search']))
- {
- if (isset($_POST['fname']))
- {
- $fname = $_POST['fname'];
- $query = "SELECT first_name, last_name, phone_number, address, city, state, zip, birth_month, birth_day, birth_year, username, password, sex, relationship, id from people where first_name = '$fname'";
- $result = $conn->query($query);
- $rows = $result->num_rows;
- for ($j = 0; $j < $rows; ++$j)
- {
- $result->data_seek($j);
- $row = $result->fetch_array(MYSQLI_NUM);
- echo <<<_END
- <pre>
- First Name: $row[0]
- Last Name: $row[1]
- Phone Number $row[2]
- Address $row[3]
- City $row[4]
- State $row[5]
- State $row[5]
- Zip $row[6]
- Birth month $row[7]
- Birth Day $row[8]
- Birth Year $row[9]
- Username $row[10]
- Password $row[11]
- Sex $row[12]
- Relationship $row[13]
- ID $row[14]
- </pre>
- _END;
- if (!$result)
- die("Database access failed: " . $conn->error);
- echo 'success!';
- }
- }
- if (isset($_POST['lname']))
- {
- $lname = $_POST['lname'];
- $query = "SELECT first_name, last_name, phone_number, address, city, state, zip, birth_month, birth_day, birth_year, username, password, sex, relationship, id from people where last_name = '$lname'";
- $result = $conn->query($query);
- $rows = $result->num_rows;
- for ($j = 0; $j < $rows; ++$j)
- {
- $result->data_seek($j);
- $row = $result->fetch_array(MYSQLI_NUM);
- echo <<<_END
- <pre>
- First Name: $row[0]
- Last Name: $row[1]
- Phone Number $row[2]
- Address $row[3]
- City $row[4]
- State $row[5]
- State $row[5]
- Zip $row[6]
- Birth month $row[7]
- Birth Day $row[8]
- Birth Year $row[9]
- Username $row[10]
- Password $row[11]
- Sex $row[12]
- Relationship $row[13]
- ID $row[14]
- </pre>
- _END;
- if (!$result)
- die("Database access failed: " . $conn->error);
- echo 'success!';
- }
- }
- }
- // UPDATE
- if (isset($_POST['update']))
- {
- $username = $_POST['myusername'];
- $run_the_query = FALSE;
- $fname = $_POST['fname'];
- $lname = $_POST['lname'];
- $phone = $_POST['phone'];
- $address = $_POST['address'];
- $city = $_POST['city'];
- $state = $_POST['state'];
- $zip = $_POST['zip'];
- $month = $_POST['month'];
- $day = $_POST['day'];
- $year = $_POST['year'];
- $myusername = $_POST['myusername'];
- $mypassword = $_POST['mypassword'];
- $sex = $_POST['sex'];
- $relation = $_POST['relation'];
- $my_string = "UPDATE people SET first_name = '$fname', last_name = '$lname', phone_number = '$phone', address = '$address', city = '$city', state = '$state', zip = '$zip', birth_month = '$month', birth_day = '$day', birth_year = '$year', password = '$mypassword', sex = '$sex', relationship = '$relation' WHERE username = '$username'";
- $result = $conn->query($my_string);
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement