I'm trying to get a list of customers from a table and then append data onto them each day. I can't figure out how to insert into the database multiple rows with the same name
I have 3 tables: Companies, jobs, reports. I'm doing a 2 loops to get the companies and jobs data from the tables into a form which is added to each day which will go into the repots table. I've tried doing it as an array and doing it in a while loop, foreach loop but each time hasn't worked. I'm going wrong somewhere i just dont know where
$companyquery = "SELECT * FROM companiestest WHERE (enabled != 'true') ORDER BY name";
$companies = $mysqli->query($companyquery);
while($company = $companies->fetch_assoc()) {
$cid = htmlspecialchars($company['id']);
$companyname = htmlspecialchars($company['name']);
echo "<tr>";
$jobquery = "SELECT * FROM jobstest WHERE (cid = " . $company['id'] . ") AND (enabled != 'true') ORDER BY jobname";
$jobs = $mysqli->query($jobquery);
while($job = $jobs->fetch_assoc()) {
$bid = htmlspecialchars($job['id']);
$product = htmlspecialchars($job['product']);
$server = htmlspecialchars($job['server']);
$medium = htmlspecialchars($job['medium']);
$jobname = htmlspecialchars($job['jobname']);
echo "<input type='hidden' name='backupid' value='$bid''>";
echo "<input type='hidden' name='companyname' value='$companyname''>";
echo "<input type='hidden' name='companyid' value='$cid'>";
echo "<td>$companyname - $cid</td>";
echo "<td>$product</td>";
echo "<td>$server</td>";
echo "<td>$medium</td>";
echo "<td>$jobname</td>";
echo "<td><select name='result' required>
<option disabled selected value>Result</option>
<option value='success'>Successful</option>
<option value='warn'>Warning</option>
<option value='fail'>Fail</option>
</select></td>";
echo "<td><input type='text' name='ticket' placeholder='Ticket Number'></td>";
echo "</tr>";
if(isset($_POST['submit'])){
$companyname = strip_tags(trim($_POST['companyname']));
$date = strip_tags(trim($_POST['date']));
$staffmember = strip_tags(trim($_POST['staff']));
$result = strip_tags(trim($_POST['result']));
$ticket = strip_tags(trim($_POST['ticket']));
$companyid = strip_tags(trim($_POST['companyid']));
$jobid = strip_tags(trim($_POST['jobid']));
$array = array();
array_push($array, $companyname, $date, $staffmember, $result, $ticket, $companyid, $jobid);
//$array = "('$companyname', '$date', '$staffmember', '$result', '$ticket', '$companyid')";
print_r($array);
$query = "INSERT INTO reporttest (company, date, staff, result, ticketnum, cid, bid) VALUES ($companyname, $date, $staffmember, $result, $ticket, $companyid, $jobid)";
//echo "$query";
}
The answer is a foreach loop with a key increment which inserts each variable into its own array. Then a foreach on the array to bind and execute into the database. Still a lot of modification to do with the data and restricting columns in the queries but so far it seems to be working without an issue.
No doubt there's a better way to do it but nobody has suggested anything to help as yet
$companyquery = "SELECT * FROM companiestest WHERE (enabled != 'true') ORDER BY name";
$companies = $mysqli->query($companyquery);
while($company = $companies->fetch_assoc()) {
$cid = htmlspecialchars($company['id']);
$companyname = htmlspecialchars($company['name']);
echo "<tr>";
$backupjobquery = "SELECT * FROM backupjobstest WHERE (cid = " . $company['id'] . ") AND (enabled != 'true') ORDER BY jobname";
$backupjobs = $mysqli->query($backupjobquery);
foreach($backupjobs as $key => $backupjob){
$key++;
$bid = htmlspecialchars($backupjob['id']);
$product = htmlspecialchars($backupjob['product']);
$server = htmlspecialchars($backupjob['server']);
$medium = htmlspecialchars($backupjob['medium']);
$jobname = htmlspecialchars($backupjob['jobname']);
echo "<input type='hidden' name='backupid[]' value='$bid'>";
echo "<input type='hidden' name='companyid[]' value='$cid'>";
echo "<td>$companyname - $cid</td>";
echo "<td>$product</td>";
echo "<td>$server</td>";
echo "<td>$medium</td>";
echo "<td>$jobname</td>";
echo "<td><select name='result[]' required>
<option disabled selected value>Result</option>
<option value='Successful'>Successful</option>
<option value='Warning'>Warning</option>
<option value='Failure'>Failure</option>
</select></td>";
echo "<td><input type='number' name='ticketnum[]' placeholder='Ticket Number'></td>";
echo "</tr>";
}
}
if(isset($_POST['submit'])){
$results = array();
$ticketnums = array();
$cids = array();
$bids = array();
$date = strip_tags(trim($_POST['date']));
$staffmember = strip_tags(trim($_POST['staff']));
foreach ($_POST['result'] as $key => $result) {
array_push($results, $result);
}
foreach ($_POST['ticketnum'] as $key => $ticketnum) {
array_push($ticketnums, $ticketnum);
}
foreach ($_POST['companyid'] as $key => $cid) {
array_push($cids, $cid);
}
foreach ($_POST['backupid'] as $key => $bid) {
array_push($bids, $bid);
}
$sql = "INSERT INTO reporttest (date, staff, result, ticketnum, cid, bid) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $mysqli->prepare($sql);
if ( !$stmt ) { die('prepare failed'); }
$stmt->bind_param("sssiii", $date, $staffmember, $result, $ticketnum, $cid, $bid);
foreach ($bids as $key => &$bid) {
$result = $results[$key];
$ticketnum = $ticketnums[$key];
$cid = $cids[$key];
$bid = $bids[$key];
if ($stmt->execute()) {
echo "Successfully updated the report";
} else {
echo "Error updating";
}
$stmt->fetch();
printf("Date: %s, Staff: %s, result: %s, Ticket: %s, cid: %s, bid: %s", $date, $staffmember, $result, $ticketnum, $cid, $bid);
echo "<br>";
}
$stmt->close();
}
Related
Okay I just changed it to $_POST and it's now working. I'm not sure if this is the shortcut method. At least it's working now. You can help me shrink the code if you want to help me. thanks
<?php
$conn = new mysqli('localhost', 'root', 'jared17', 'hbadb')
or die ('Cannot connect to db');
$result = $conn->query("select * from english");
echo "<html>";
echo "<body>";
echo "<form method = POST>";
echo "<select name = 'Students'>";
while ($row = $result->fetch_assoc()) {
$LRN = $row['LRN'];
$Last = $row['Last_Name'];
$First = $row['First_Name'];
$Lvl = $row['Level'];
$Q1 = $row['Q1'];
$Q2 = $row['Q2'];
$Q3 = $row['Q3'];
$Q4 = $row['Q4'];
$Final = $row['FINAL'];
echo '<option value="'.$LRN.'|'.$Last.', '.$First.'|'.$Lvl.'|'.$Q1.'|'.$Q2.'|'.$Q3.'|'.$Q4.'|'. $Final.'">'.$Last.', '.$First.'</option>';
}
echo "</select>";
echo "<input type='submit' name='submit' value='Show'>";
echo "</form>";
$show = $_POST['Students'];
$show_explode = explode('|', $show);
echo "<table><tr><th>LRN</th><th>Name</th><th>Level</th><th>Q1</th><th>Q2</th><th>Q3</th><th>Q4</th><th>Final</th></tr>";
echo "<tr><td>". $show_explode[0]."</td><td>". $show_explode[1]."</td><td>". $show_explode[2]."</td><td>". $show_explode[3]."</td><td>". $show_explode[4]."</td><td>". $show_explode[5]."</td><td>". $show_explode[6]."</td><td>". $show_explode[7]."</td></tr>";
echo "</table>";
echo "</body>";
echo "</html>";
?>
Don't put all the details in the option value like that. Just put the ID in the value.
echo "<select name = 'Students'>";
while ($row = $result->fetch_assoc()) {
$LRN = $row['LRN'];
$Last = $row['Last_Name'];
$First = $row['First_Name'];
echo '<option value="'.$LRN.'">'.$Last.', '.$First.'</option>';
}
echo "</select>";
Then look it up in the database when the form is submitted.
if (isset($_POST['Students'])) {
$lrn = $_POST['Students'];
$stmt = $conn->prepare("SELECT Last_Name, First_Name, Level, Q1, Q2, Q3, Q4, FINAL FROM english WHERE LRN = ?");
$stmt->bind_param('i', $lrn);
$stmt->execute();
$stmt->bind_result($last, $first, $level, $q1, $q2, $q3, $q4, $final);
$stmt->fetch();
echo "<table><tr><th>LRN</th><th>Name</th><th>Level</th><th>Q1</th><th>Q2</th><th>Q3</th><th>Q4</th><th>Final</th></tr>";
echo "<tr><td>$lrn</td><td>$last, $first</td><td>$level</td><td>$q1</td><td>$q2</td><td>$q3</td><td>$q4</td><td>$final</td></tr></table";
}
You can use $foreach for minimum code when deal with Array. Here code goes
if(isset($_POST['submit'])){
// after post a form ur code goes here
$show = $_POST['Students']; $show_explode = explode('|', $show);
echo "<table><tr>
<th>LRN</th>
<th>Name</th>
<th>Level</th>
<th>Q1</th>
<th>Q2</th>
<th>Q3</th>
<th>Q4</th>
<th>Final</th>
</tr>";
echo "<tr>";
foreach($show_explode as $value){
echo "<td>".$value."</td>";
}
echo "</tr></table>
}
Is it possible to while loop an entire select tag to have multiple dropdown menus?
What I am trying to achieve is to have a column full of dropdown menus in a table.
This is what I have tried so far
<?php
$DNS_FROM = $DNS."_port-%";
$select = "SELECT * FROM `uplink_port_mapping` WHERE DNS_From LIKE '$DNS_FROM'";
$select1 = mysqli_query($conn, $select);
$select2 = "SELECT DNS_From FROM `uplink_port_mapping` WHERE DNS_From NOT LIKE '$DNS_FROM' AND DNS_To = ''";
$select3 = mysqli_query($conn, $select2);
while($uplink_from = mysqli_fetch_assoc($select1)){
echo "<tr>";
echo "<td>".$uplink_from['DNS_From']."</td>";
echo "<td>"."<select name = 'uplink_to' multiple='multiple'>
<option value = '".$uplink_from['DNS_To']."' selected='selected'>". $uplink_from['DNS_To']."</option>";
while ($uplink_to = mysqli_fetch_assoc($select3)){
echo "<option value='".$uplink_to['DNS_From']."'>".$uplink_to['DNS_From']."</option>";
}
echo"</select>";
echo"</td>";
echo"</tr>";
}
?>
How it is right now.
The reason for the second while loop only working once is, that mysqli_fetch_assoc($result) will leave the pointer of the $result recource at it's end.
So when you try to loop the second time, mysqli_fetch_assoc($result) will not return anything (cause it's at the end of the $result recource.
Two possibilites:
Reset the pointer to the beginning:
<?php
....
while($uplink_from = mysqli_fetch_assoc($select1)){
echo "<tr>";
echo "<td>".$uplink_from['DNS_From']."</td>";
echo "<td>"."<select name = 'uplink_to' multiple='multiple'>
<option value = '".$uplink_from['DNS_To']."' selected='selected'>". $uplink_from['DNS_To']."</option>";
// here's the change:
mysql_data_seek($select3, 0);
while ($uplink_to = mysqli_fetch_assoc($select3)){
echo "<option value='".$uplink_to['DNS_From']."'>".$uplink_to['DNS_From']."</option>";
}
echo"</select>";
echo"</td>";
echo"</tr>";
}
....
?>
Or - which I think is the better solution - store that data into an array first, and then walk through that array:
<?php
...
$select2 = "SELECT DNS_From FROM `uplink_port_mapping` WHERE DNS_From NOT LIKE '$DNS_FROM' AND DNS_To = ''";
$result2 = mysqli_query($conn, $select2);
$dns_from = Array();
while ($uplink_to = mysqli_fetch_assoc($select3)){
$dns_from[] = $uplink_to;
}
....
// inside your first while loop:
foreach($dns_from as $dns) {
echo "<option value='".$dns['DNS_From']."'>".$dns['DNS_From']."</option>";
}
....
// note that I left out a bunch of your code, that doesn't change.
?>
Multiple select dropdown basic examples
$array = [
'Apple' => 1,
'Orange' => 0,
'Banana' => 1,
];
echo '<select multiple>';
foreach ($array as $fruit => $sel) {
$selected = 0;
if ($sel == 1) {
$selected = 'selected';
}
echo '<option value="' . $fruit . ' " ' . $selected . '>' . $fruit . '</option>';
}
echo '</select>';
Below I have Php code that loops through an array and for each it checks if the value already exists in the database and if not, create it. The code itself is working but the loop itself can be insanely big, maximum of a couple tens thousand iterations.
How can I optimize this code? What to use and how to use. There should be a better way to insert this many times without looping through each individual.
foreach($arr as $value){
$checkID = mysqli_query($cenn, "SELECT item_id from items WHERE item_id = '$value'");
if (!$checkID) {
die("Query '$checkID' failed to execute for some reason");
}else{
if (mysqli_num_rows($checkID) > 0) {
$user = mysqli_fetch_array($checkID);
echo "item_id" . checkID . "exists already";
}
else{
echo "item_id: '$user_id' doesn't exist<br>";
$gw2Api = file_get_contents("https://api.guildwars2.com/v2/items/" . $user_id); //12452 30704
$gw2Api_result = json_decode($gw2Api,true);
/*Here would be some code to determine values that are being inserted*/
if (!array_key_exists("description",$gw2Api_result)) {
$description = 'No description available...';
} else{
if($gw2Api_result['description'] === ''){
$description = "No description available...";
} else {
$description = $gw2Api_result['description'];
}
}
$insertItem = "INSERT INTO items
(item_id, name, description,
AccountBindOnUse, AccountBound,
last_update
)
VALUES ('$user_id', '$gw2Api_result[name]', '$description',
'$AccountBindOnUse', '$AccountBound', CURRENT_TIMESTAMP)";
if ($cenn->query($insertItem) === true) {
echo "New record '$user_id' created successfully";
} else {
echo "Error: " . $sql . "<br>" . $cenn->error;
}
}
}
} // end foreach
The question: How to insert many values, new rows, into mysqli database as fast as possible.
Just use bulk insert.
Collect all the rows for insertion and pass it in one query.
echo 'hi';
if (!empty($arr)) {
echo 'ok';
$values = "'" . implode("', '", $arr) . "'";
$qExistingItemIds = mysqli_query($cenn, "SELECT item_id from items WHERE item_id IN($values)");
$existingItemIds = [];
while ($existingItemId = mysqli_fetch_array($qExistingItemIds)) {
$existingItemIds[] = $existingItemId['item_id'];
}
$arr = array_diff($arr, $existingItemIds);
$inserts = array();
$i = 0;
$ic = count($arr);
foreach ($arr as $value) {
$i++;
echo "item_id: $value doesn't exist<br>";
$gw2Api = file_get_contents("https://api.guildwars2.com/v2/items/" . $value); //12452 30704
$gw2Api_result = json_decode($gw2Api,true);
/*Here would be some code to determine values that are being inserted*/
if (!array_key_exists("description", $gw2Api_result)) {
$description = 'No description available...';
} else {
if ($gw2Api_result['description'] === '') {
$description = "No description available...";
} else {
$description = $gw2Api_result['description'];
}
}
$inserts[] = "
('$value', '$gw2Api_result[name]', '$description', '$AccountBindOnUse', '$AccountBound', CURRENT_TIMESTAMP)
";
if ($i == 50 OR $i == $ic) {
$inserts = implode(",", $inserts);
$insert = "
INSERT INTO items
(item_id, name, description, AccountBindOnUse, AccountBound, last_update)
VALUES
$inserts
";
if ($cenn->query($insert) === true) {
echo 'great';
echo "New records created successfully";
} else {
echo "Error: " . $sql . "<br>" . $cenn->error;
}
$ic -= 50;
$i = 0;
$inserts = array();
}
}
}
so now we have only 2 queries. not thousands
details about bulk insert:
http://www.geeksengine.com/database/data-manipulation/bulk-insert.php
If you use prepared statement you should reduce the round trips to the database server and only compile and optimise each query once instead of Number_of_inputs * 2 queries. This should reduce the workload.
I would be very interested to know by how much.
$sql = "SELECT item_id from items WHERE item_id = ?";
$db_select = $cenn->prepare($sql);
if ( ! $db_select ) {
echo $cenn->error;
exit;
}
$sql_insert = "INSERT INTO items
(item_id, name, description,
AccountBindOnUse, AccountBound, last_update)
VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP)";
$db_insert = $cenn->prepare($sql);
if ( ! $db_insert ) {
echo $cenn->error;
exit;
}
foreach($arr as $value){
$db_select->bind_param('i', $value);
$res = $db_select->execute()
if ( $res === FALSE ) {
echo $cenn->error;
exit;
}
if ($db_select->num_rows > 0) {
// dont bother fetching data we already know all we need to
$user = $db_select->free();
echo "item_id $value exists already";
} else {
echo "item_id: $value doesn't exist<br>";
$gw2Api = file_get_contents("https://api.guildwars2.com/v2/items/" . $value);
$gw2Api_result = json_decode($gw2Api,true);
if ( ! array_key_exists("description",$gw2Api_result)
|| $gw2Api_result['description'] === '') {
$description = 'No description available...';
} else{
$description = $gw2Api_result['description'];
}
$db_insert->bind_param('issss', $value, $gw2Api_result[name],
$description, $AccountBindOnUse,
$AccountBound)
if ($cenn->query($insertItem) === true) {
echo "New record $value' created successfully";
} else {
echo "Error: " . $sql_insert . "<br>" . $cenn->error;
}
}
} // end foreach
I have 2 textbox array,
questions & correct answer...
the problem is , i cannot save it to the the database
questions should be saved to "test" field in database
and correct answer should be saved to "test2" field...
code for the textbox
echo "<label for='textfield[]' align='left'> Question </label>";
echo "<br/>";
echo "<input type='text' name='textfield[]'>";
echo "<br/>";
echo "<label for='textfield2[]' align='left'> Correct Answer </label>";
echo "<br/>";
echo "<input type='text' name='textfield2[]'>";
echo "<br/>";
code for inserting values in database
$sql = array();
foreach($_POST['textfield'] as $textfield){
foreach($_POST['textfield2'] as $textfield2){
$sql[] = "INSERT INTO practice (test,test2) VALUES ('{$textfield}','{$textfield2}')";
}
}
foreach($sql as $query){
mysqli_query($con,$query);
}
}
You can insert like this,
<?php
$post_count = count($_POST['textfield']);
$post1 = array();
$post2 = array();
$post1 = $_POST['textfield'];
$post2 = $_POST['textfield2'];
for ($i = 0; $i <= $post_count; $i++) {
$sql[] = "INSERT INTO practice (test,test2) VALUES ('".$post1[$i]."','".$post2[$i]."')";
}
foreach ($sql as $query) {
mysqli_query($con, $query);
}
?>
I am trying to delete a user from my simple E-commerce website for a project I am working on. When I click the delete button, the message appears and tells me that it correctly deleted the data from the table. But when I go into my sql database and check the data, its all still there. I cant figure out what I am doing wrong or where my error is. any help would be appreciated. My code is below.
<?php
session_start();
if (isset($_SESSION['shirt_users_id']) && isset($_SESSION['full_name'])) {
require('mysql_connect.php');
$title="List all registered users";
include_once("header_admin.php");
if (isset($_GET['shirt_users_id'])) {
$shirt_users_id = $_GET['shirt_users_id'];
function rollback_die($msg)
{
echo $msg;
global $link;
mysqli_query($link, "ROLLBACK");
mysqli_free_result($exec_select_sui);
mysqli_close($link);
include("footer_admin.php");
die();
}
function delete_records($array_refer)
{
global $link;
foreach ($array_refer as $key => $array_value) {
$table_name = substr($key, 0, -3);
foreach ($array_value as $value) {
$delete = "DELETE from $table_name where $key = $value";
$exec_delete = #mysqli_query($link, $delete);
if (!$exec_delete) {
rollback_die("Records from $table_name could not be deleted because of: ".mysqli_error($link));
}
}
}
return true;
}
#mysqli_query($link, "SET AUTOCOMMIT=0");
$select_sui = "SELECT shirt_users.shirt_users_id, shirt_users_types.shirt_users_types_id, shirt_orders.shirt_orders_id, shirt_shipping_addresses.shirt_shipping_addresses_id, shirt_billing_addresses.shirt_billing_addresses_id, shirt_credit_cards.shirt_credit_cards_id
from
shirt_users, shirt_users_types, shirt_orders, shirt_shipping_addresses, shirt_billing_addresses, shirt_credit_cards
where
shirt_users.shirt_users_id = shirt_users_types.shirt_users_id and
shirt_users_types.shirt_orders_id = shirt_orders.shirt_orders_id and
shirt_orders.shirt_shipping_addresses_id = shirt_shipping_addresses.shirt_shipping_addresses_id and
shirt_orders.shirt_billing_addresses_id = shirt_billing_addresses.shirt_billing_addresses_id and
shirt_orders.shirt_credit_cards_id = shirt_credit_cards.shirt_credit_cards_id and
shirt_users.shirt_users_id = $shirt_users_id";
$exec_select_sui = #mysqli_query($link, $select_sui);
if (!$exec_select_sui) {
rollback_die("A problem when retrieving records from the database for shirt user has occurred: ".mysqli_error($link));
} else {
$users = $gut = $orders = $shipping = $billing = $credit = array();
while ($one_row = mysqli_fetch_assoc($exec_select_sui)) {
$users[] = $one_row['shirt_users_id'];
$gut[] = $one_row['shirt_users_types_id'];
$orders[] = $one_row['shirt_orders_id'];
$shipping[] = $one_row['shirt_shipping_addresses_id'];
$billing[] = $one_row['shirt_billing_addresses_id'];
$credit[] = $one_row['shirt_credit_cards_id'];
}
$multi_array = array('shirt_users_id' => $users, 'shirt_users_types_id' => $gut, 'shirt_orders_id' => $orders, 'shirt_shipping_addresses_id' => $shipping, 'shirt_billing_addresses_id' => $billing, 'shirt_credit_cards_id' => $credit);
delete_records($multi_array);
echo "the record(s) of shirt user have successfully been deleted from the tables";
mysqli_query($link, "COMMIT");
}
}
(isset($_GET['sort']))?$sort = $_GET['sort']:$sort = 'ui';
(isset($_GET['bool']))?$bool = $_GET['bool']:$bool=true;
switch ($sort) {
case 'ui': ($bool)?$sort = "user_id ASC":$sort = "user_id DESC";
break;
case 'fn': ($bool)?$sort = "first_name ASC":$sort = "first_name DESC";
break;
case 'ln': ($bool)?$sort = "last_name ASC":$sort = "last_name DESC";
break;
case 'em': ($bool)?$sort = "email ASC":$sort = "email DESC";
break;
}
$select_users = "SELECT shirt_users_id, user_id, first_name, last_name, email from shirt_users order by $sort";
$exec_select_users = #mysqli_query($link, $select_users);
if (!$exec_select_users) {
echo "The user information could not be retrieved from the shirt_users table because of: ".mysqli_error($link);
mysqli_close($link);
include('footer_admin.php');
die();
} else {
echo "<div id='list_users'><table id='list_user' border='0'>";
echo "<tr>";
echo "<th><a href='".$_SERVER['PHP_SELF']."?sort=ui&bool=".!$bool."'>User ID</a></th>";
echo "<th><a href='".$_SERVER['PHP_SELF']."?sort=fn&bool=".!$bool."'>First Name</a></th>";
echo "<th><a href='".$_SERVER['PHP_SELF']."?sort=ln&bool=".!$bool."'>Last Name</a></th>";
echo "<th><a href='".$_SERVER['PHP_SELF']."?sort=em&bool=".!$bool."'>Email</a></th>";
echo "<th>Delete</th>";
echo "</tr>";
while ($one_row = mysqli_fetch_assoc($exec_select_users)) {
echo "<tr>";
echo "<td class='first'>".$one_row['user_id']."</td>";
echo "<td class='second'>".$one_row['first_name']."</td>";
echo "<td class='third'>".$one_row['last_name']."</td>";
echo "<td class='fourth'>".$one_row['email']."</td>";
echo "<td class='fifth'><a href='".$_SERVER['PHP_SELF']."?shirt_users_id=".$one_row['shirt_users_id']."'>Delete</a></td>";
echo "</tr>";
}
echo "<tr><td colspan = '4' class='footer'>Total number of users: </td><td class='footer'>".mysqli_num_rows($exec_select_users)."</td></tr>";
echo "</table></div>";
}
mysqli_free_result($exec_select_users);
} else {
echo "You are not an authentic administrator. Being directed to the login page...";
header("Refresh: 2; url='login.php'");
}
mysqli_close($link);
include("footer.php");
die();
?>
Also, I know my code is not the most efficient way to do things but im new to the whole html/css/php scene and am trying my best so please dont give me some off the wall answer about a differnt way to do this please!