I'm trying to display MySQL database information into HTML. I've researched 20+ topics in this forum on the subject, trying to use their solutions, yet I am still having issues. The following code is being executed. I'm trying to read the courseNumber, section, instructor, startTime, endTime, days, and name from a database. I thought that the foreach would display all of my data from the query, but there is nothing being displayed, only my table headers and user input button at the bottom. I have made sure that the database is populated. I've attempted to use a while loops and different foreach loops from online solutions, but haven't had any luck. If it isn't obvious, I'm a programming student and am trying to get a grasp on the subject. All time and effort is greatly appreciated!
this is the website i'm uploading to http://einstein.etsu.edu/~latture/hw4/main.php
//this is the function I'm using to call my database. This part is working correctly(executed below)
static function readAll()
{
$pdo = Database::connect();
$sql = "Select * from course";
$data = $pdo->prepare($sql);
$data->execute();
$data->fetchAll();
Database::disconnect();
return $data;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<style>
label{display:inline-block;width:100px;margin-bottom:10px;}
</style>
<title></title>
</head>
<body>
<div class="row">
<div class="col">
<table class="table">
<thead>
<tr>
<th>Course Number</th>
<th>Section</th>
<th>Instructor</th>
<th>Start Time</th>
<th>End Time</th>
<th>Days</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<?php
include_once "courseController.php";
include_once "schedule.php";
include_once "student.php";
$courses = courseController::readAll();
foreach($courses as $courseDB) {
echo '<tr>' .
'<td>' . $courseDB['courseNumber'] . '</td>' .
'<td>' . $courseDB['section'] . '</td>' .
'<td>' . $courseDB['startTime'] . '</td>' .
'<td>' . $courseDB['endTime'] . '</td>' .
'<td>' . $courseDB['instructor'] . '</td>' .
'<td>' . $courseDB['days'] . '</td>' .
'<td>' . $courseDB['name'] . '</td>' .
'</tr>';
}
?>
</tbody>
</table>
</div>
</div>
<div class="row">
<form = method ="post" action = "process.php">
<div class = "col">
<div class="form-group">
<select class="form-control" name="ActionType">
<option id="create" value="create">Create!</option>
<option id="update" value="update">Update..</option>
<option id="delete" value="delete">Delete :(</option>
</select>
</div>
</div>
<div class = "col">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</form>
</div>
</body>
</html>
You have to return result received from $data->execute();. change your readAll() as below
static function readAll()
{
$records = array();
$pdo = Database::connect();
$sql = "Select * from course";
$data = $pdo->prepare($sql);
$data->execute();
$records = $data->fetchAll();
Database::disconnect();
return $records;
}
you should use this
$data= $pdo->query($sql);
$result = $query->rowCount();
if($result > 0){
$r = $result->fetchAll();
}else{
$r = 0;
}
return $r;
Related
I am creating the form to select all option to show in the below table, I want to search when I am selected the option show in the table. My part to do is let me to onchange "Transaction Type" then show the below table. How to function can let me to select all option to show in the below table? Hope anyone can give me example or edit in my coding to guide me how to do it. I want the output can follow my select date range and transaction type to show the table.
transaction_history file to show the frontend create the form and pass the data to the backend.
<?php
$system_user_type = $user_type;
$lang = $_COOKIE["Language"];
$new_cur_date = date("d-m-Y", strtotime($cur_date));
require_once("language/lang_transaction_" . $lang . ".php");
?>
<html>
<head>
</head>
<body>
<div class="row">
<div class="col-lg-12">
<div class="box form-group">
<header>
<h5><?php echo $language["LIST_TITLE1"]; ?></h5>
<!-- .toolbar -->
<div class="toolbar">
<nav style="padding: 8px;">
<a href="javascript:;" class="btn btn-default btn-xs collapse-box">
<i class="fa fa-minus"></i>
</a>
</nav>
</div><!-- /.toolbar -->
</header>
<section class="content">
<div class="col-lg-12 form-group" >
<label for="text1" class="form-group control-label col-lg-2"><?php echo $language['type']; ?>:</label>
<div class="col-lg-2">
<select id="select_type" class="form-group form-control required" onchange="show_table();">
<option value="transfer" selected><?php echo $language["transfer"]; ?></option>
<option value="withdraw"><?php echo $language["withdraw"]; ?></option>
<option value="upgrade"><?php echo $language["upgrade"]; ?></option>
<option value="register">Register</option>
<option value="receive"><?php echo $language["receive"]; ?></option>
</select>
</div>
<div class="col-lg-8"></div>
</div>
<div class="col-lg-12 form-group">
<label for="text1" class="form-group control-label col-lg-2">Date Range:</label>
<div class="col-lg-2">
<?php echo custom_period_opt(); ?>
</div>
<label for="text1" class="form-group control-label col-lg-2">Date Created</label>
<div class="col-lg-2">
<input type="text" class="form-group form-control datepicker" id="start_date" name="start_date" data-date-format="dd-mm-yyyy" title="" value="<?php echo $new_cur_date; ?>" readonly>
</div>
<label for="text1" class="form-group control-label col-lg-2">To</label>
<div class="col-lg-2">
<input type="text" class="form-group form-control datepicker" id="end_date" name="end_date" data-date-format="dd-mm-yyyy" title="" value="<?php echo $new_cur_date; ?>" readonly>
</div>
</div>
<div class="col-lg-12" style="text-align:center; padding-bottom:10px; padding-top:10px;">
<button id="search_button" type="button" class="btn btn-sm btn-primary" onclick="search2_('search', 'bill_table', 'billing');">Search</button>
<button id="clear" type="button" class="btn btn-sm btn-default" onclick="clearData()">Clear</button>
</div>
<div class="" id="table_result">
</div>
</section>
</div>
</div>
</div>
</body>
</html>
<script>
$(function() {
show_table();
$("#select_type").on("change", function() {
show_table();
});
});
function show_table() {
//alert(123);
var select_type = $("#select_type").val();
$.ajax({
url: "?f=transaction_table",
type: "POST",
data: {
select_type: select_type
},
before_send: function() {
show_overLay();
//$('#patient_result').html('');
},
success: function(data) {
hide_overLay('');
//alert(data);
if (data) {
$("#table_result").html("");
$("#table_result").append(data);
//
$('.dataTable').dataTable();
} else {
alert("Please fill in the field.");
}
}
});
}
</script>
<style>
.myClass
{
display: none;
}
</style>
transaction_table file to show the backend function send to frontend page.Below is my coding:
<?php
$select_type = $_POST['select_type'];
if ($select_type == "withdraw") {
echo '<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>No</th>
<th>Date</th>
<th>Amount</th>
</tr>
</thead>
<tbody>';
$i = 1;
$select_transfer = 'SELECT * FROM withdrawal_record bp WHERE user_id = ' . $user_id . ' ORDER BY created';
$arr_transfer = db_conn_select($select_transfer);
foreach ($arr_transfer as $rs_transfer) {
echo '<tr>';
echo '<td>' . $i++ . '</td>';
echo '<td>' . date('d-m-Y', strtotime($rs_transfer['created'])) . '</td>';
echo '<td>' . $rs_transfer['withdraw_amount'] . '</td>';
echo '</tr>';
}
echo " </tbody>
</table>";
}elseif ($select_type == "transfer") {
?>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>No</th>
<th>Date</th>
<th>To Type</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$select_transfer = 'SELECT * FROM transfer_history_bp WHERE user_id = ' . $user_id . ' ORDER BY created';
$arr_transfer = db_conn_select($select_transfer);
foreach ($arr_transfer as $rs_transfer) {
if($rs_transfer['point_type']=="2"){
$to_type="Register Point";
}elseif($rs_transfer['point_type']=="3"){
$to_type="Entertainment Point";
}elseif($rs_transfer['point_type']=="4"){
$to_type="Business Point";
}
echo '<tr>';
echo '<td>' . $i++ . '</td>';
echo '<td>' . date('d-m-Y', strtotime($rs_transfer['created'])) . '</td>';
echo '<td>' . $to_type . '</td>';
echo '<td>' . $rs_transfer['total_amount'] . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<?php
}elseif ($select_type == "upgrade") {
?>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>No</th>
<th>Date</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$select_transfer = 'SELECT * FROM upgrade_point WHERE user_id = ' . $user_id . ' ORDER BY created';
$arr_transfer = db_conn_select($select_transfer);
foreach ($arr_transfer as $rs_transfer) {
echo '<tr>';
echo '<td>' . $i++ . '</td>';
echo '<td>' . date('d-m-Y', strtotime($rs_transfer['created'])) . '</td>';
echo '<td>' . $rs_transfer['total_amount'] . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<?php
}elseif ($select_type == "register") {
?>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>No</th>
<th>Date</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$select_transfer = 'SELECT * FROM transfer_history_rp WHERE user_id = ' . $user_id . ' and created between "2019-11-01 12:25:05" and "2099-11-01 12:25:05" and use_type=1 ORDER BY created';
$arr_transfer = db_conn_select($select_transfer);
foreach ($arr_transfer as $rs_transfer) {
echo '<tr>';
echo '<td>' . $i++ . '</td>';
echo '<td>' . date('d-m-Y', strtotime($rs_transfer['created'])) . '</td>';
echo '<td>' . $rs_transfer['total_amount'] . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<?php
}elseif ($select_type == "receive") {
?>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>No</th>
<th>Date</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$select_transfer = 'SELECT * FROM extra_point WHERE user_id = ' . $user_id . ' ORDER BY created';
$arr_transfer = db_conn_select($select_transfer);
foreach ($arr_transfer as $rs_transfer) {
echo '<tr>';
echo '<td>' . $i++ . '</td>';
echo '<td>' . date('d-m-Y', strtotime($rs_transfer['created'])) . '</td>';
echo '<td>' . $rs_transfer['total_amount'] . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<?php
}
?>
Below is my output, this output just can follow what I select the transaction type to onchange to show in the table:
Below is my database information:
If I understand your question correctly, then you need to include these additional parameters in your request as you already to with select_type.
First, get the additional values in theshowTable function, also add them to the request data:
function show_table() {
var select_type = $("#select_type").val();
var start_date = $("#start_date").val();
var end_date = $("#end_date").val();
$.ajax({
url: "?f=transaction_table",
type: "POST",
data: {
select_type: select_type,
start_date: start_date,
end_date: end_date
},
// ...
}
then, receive the values in your PHP file like you already do with select_type:
<?php
$select_type = $_POST['select_type'];
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
// ...
Finally, you have to adjust your queries accordingly. As you already have and created between "2019-11-01 12:25:05" and "2099-11-01 12:25:05" in your queries, it's just a matter of replacing the hardcoded dates with the ones you received. Do not forget to sanitize your input dates! If possible use prepared statements.
Note 1: Your script and style tags are outside of the html part of your site. This is not valid. These tags belong into either the head or the body tag.
Note 2: There are whitespaces before your opening html tag. You may wan't to avoid this too, since it can trigger IE into quirks mode. Simply change this
?>
<html>
to this
?><html>
I have been staring at this for literally two hours trying to fix it. Any help would be appreciated. For some reason the table isn't being loaded when the button is clicked.
Here's the relevant part of my head:
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" />
</head>
This is my table:
<div class="container">
<div class="midtxt">
<div id = "transactions-sav" style="margin-top: 0;">
<h2>Most Recent Transactions</h2>
<table>
<thead>
<tr>
<th>Username</th>
<th>Amount</th>
<th>Time & Date</th>
<th>Account Type</th>
</tr>
</thead>
<tbody>
<div id="trans-div">
</div>
</tbody>
</table>
<hr />
</div>
</div>
<a class="btn light-blue waves-effect waves-light table-end" id="trans-more" style="margin-top: 35px;">Load More Transactions</a>
</div>
This is my Ajax transmitter:
<script>
$(document).ready(function() {
let transCount = 20;
$('#trans-more').on('click', function() {
transCount += 20;
console.log('click');
console.log(transCount);
$('#trans-div').load('includes/loadtranshistajax.inc.php', {transNewCount: transCount,user_id: <?php echo $_SESSION['user_id']; ?>}, function() {
console.log('callback');
});
});
console.log('test1');
});
</script>
This is my PHP script for generating the table. It is worth noting that initialize() starts a session.:
<?php
require_once 'dbc-stu.inc.php';
require_once 'initialize.inc.php';
require_once 'app/transactions/transhist.inc.php';
initialize();
initialize_secure();
//Import the count
$limit = $_POST['transNewCount'];
$userID = $_SESSION['user_id'];
$sql = "SELECT * FROM transactions WHERE trans_targetID ='$userID' ORDER BY trans_time DESC LIMIT $limit";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr>';
foreach ($row as $key => $value) {
if ($key === 'trans_time') {
$time = $value;
date_default_timezone_set("America/Los_Angeles");
$time = date("F j, Y, g:i a",$time);
} elseif ($key === 'trans_amount') {
$amnt = $value;
} elseif ($key ==='trans_targetID') {
$username = idToUsername($value);
} elseif ($key === 'trans_accType') {
$accType = $value;
}
}
echo '<td>' . $username . '</td>';
echo '<td>' . $amnt . '</td>';
echo '<td>' . $time . '</td>';
echo '<td>' . $accType . '</td>';
echo '</tr>';
}
Edit, thanks a lot everybody. I'm fairly new to the web development community, so it's cool to see everyone help out!
Remove div tag from tag and add id in tbody attribute as below.
<tbody id="trans-div"></tbody>
Put the php code<?php echo $_SESSION['user_id']; ?> inside a <script> tag into double quote as it's causing the SyntaxError which break` your script code.
That's why you are not able to view XHR into console
Try the following:
$('#trans-div').load('includes/loadtranshistajax.inc.php', {transNewCount: transCount,user_id: "<?php echo $_SESSION['user_id']; ?>"}, function() {
console.log('callback');
});
I have been scouring the stack-overflow site and tried most of the similar questions that had been asked/answered, but unfortunately none of the solutions have worked for me so far. I am trying to have a list that is being populated by an sql database (which is working) and then once selecting the item, hitting the "generate" button and grabbing the data from the table and posting ONLY the selected data into the table. Previously I had an issue where the tables where being populated with ALL the data from the weapons list. After working on it some I have am now getting the error "Unknown column (whichever weapon name I choose) in where clause 107 (which I am assuming is my line number). Any suggestions?
Here is the entirety of the form from populating the list from the database to trying to select the weapon from the list.
<form action="#" method="post">
<table class="table">
<thead>
Martial Weapon Name
</thead>
<tr>
<th>
<select name="Choosen">
<?php
echo'<option>Select Weapon</option>';
//Check if at least one row is found
if($result->num_rows >0){
//Loop through results
while($row = $result->fetch_assoc()){
//Display weapon info
$output = $row['weapon_name'];
echo '<option>'.$output.'</option>';
}
}
?>
</select>
</th>
</tr>
</table>
<input class="btn btn-default" type="submit" name="submit" value="Generate">
<h3>
Weapon
</h3>
<table class="table table-striped">
<tr>
<th>
Weapon Name
</th>
<th>
Weapon Type
</th>
<th>
Damage
</th>
</tr>
<?php
if (isset($_POST['submit'])) {
$selected_weapon = $_POST['Choosen'];
$choose = "SELECT
weapon_types_martial.id,
weapon_types_martial.weapon_name,
weapon_types_martial.weapon_type,
weapon_types_martial.weapon_damage
FROM weapon_types_martial WHERE weapon_types_martial.weapon_name = " . $selected_weapon;
$result = $mysqli->query($choose) or die($mysqli->error . __LINE__);
foreach ($result->fetch_assoc() as $item) {
//Display weapon
$show = '<tr>';
$show .= '<td>' . $item['weapon_name'] . '</td>';
$show .= '<td>' . $item['weapon_type'] . '</td>';
$show .= '<td>' . $item['weapon_damage'] . '</td>';
$show .= '</tr>';
//Echo output
echo $show;
}
}
?>
</table>
</form>
And lastly here is the screenshot of what I am getting
1)You will not get data in $_POST['choosen'] As you haven't pass value in dropdown(select)
2)In your database table may be field weapon_name is varchar so you have to pass it into single quote.
Change your code as below:
<form action="#" method="post">
<table class="table">
<thead>
Martial Weapon Name
</thead>
<tr>
<th>
<select name="Choosen">
<?php
echo '<option>Select Weapon</option>';
//Check if at least one row is found
if($result->num_rows >0){
//Loop through results
while($row = $result->fetch_assoc()){
//Display weapon info
$output = $row['weapon_name'];
echo '<option value="'.$output.'">'.$output.'</option>'; //<--------------change here
}
}
?>
</select>
</th>
</tr>
</table>
<input class="btn btn-default" type="submit" name="submit" value="Generate">
<h3>
Weapon
</h3>
<table class="table table-striped">
<tr>
<th>
Weapon Name
</th>
<th>
Weapon Type
</th>
<th>
Damage
</th>
</tr>
<?php
if (isset($_POST['submit'])) {
$selected_weapon = $_POST['Choosen'];
$choose = "SELECT
id,
weapon_name,
weapon_type,
weapon_damage
FROM weapon_types_martial WHERE weapon_name = '$selected_weapon'"; //<--------------change here
$result = $mysqli->query($choose) or die($mysqli->error . __LINE__);
if ($result->num_rows > 0) {
while($item = $result->fetch_assoc()) {
//Display weapon
$show = '<tr>';
$show .= '<td>' . $item['weapon_name'] . '</td>';
$show .= '<td>' . $item['weapon_type'] . '</td>';
$show .= '<td>' . $item['weapon_damage'] . '</td>';
$show .= '</tr>';
//Echo output
echo $show;
}
}
else
{
echo "No data found";
}
}
?>
</table>
</form>
You need to place quotes in your SQL query.
Try:
$choose = "SELECT
weapon_types_martial.id,
weapon_types_martial.weapon_name,
weapon_types_martial.weapon_type,
weapon_types_martial.weapon_damage
FROM weapon_types_martial WHERE weapon_types_martial.weapon_name = '" . $selected_weapon . "'";
Word of advice, this query is very unsafe. I suggest using a framework or library for database queries.
You need to give value inside single quotes,
$choose = "SELECT
weapon_types_martial.id,
weapon_types_martial.weapon_name,
weapon_types_martial.weapon_type,
weapon_types_martial.weapon_damage
FROM weapon_types_martial
WHERE weapon_types_martial.weapon_name = '" . $selected_weapon ."'";
$choose = "SELECT id, weapon_name, weapon_type, weapon_damage FROM weapon_types_martial WHERE weapon_name = '".$selected_weapon."'";
or
$choose = "SELECT weapon_types_martial.id, weapon_types_martial.weapon_name, weapon_types_martial.weapon_type, weapon_types_martial.weapon_damage FROM weapon_types_martial as weapon_types_martial WHERE weapon_types_martial.weapon_name = '" . $selected_weapon ."'";
The options in your select element don't have a value=.. attribute, meaning that nothing is present in your query.
So $_POST['Choosen'] will = ''.
Not to mention that you're trying to pass a string, so your query will need to be wrapped in ':
$choose = "SELECT id, weapon_name, weapon_type, weapon_damage FROM weapon_types_martial WHERE weapon_name = '".$selected_weapon."'";
Hi I'm very new to PHP because I just started learning this 2 days ago!
I'm trying to display my second table properly in my index.html file but I get this error: Invalid argument supplied for foreach() Take a look
Any help would be much appreciated
Class
public class Category {
public int Id{get;set;}
public string Name {get;set;}
}
public class Product{
public int Id{get;set;}
public int CategoryId{get;set;}
public String Brand {get;set;}
public String Name {get;set;}
public decimal Price{get;set;
}
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<h3>PHP CRUD Grid</h3>
</div>
<div class="row">
<p>
Create
</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Id</th>
<th>CategoryId</th>
<th>Brand</th>
<th>Name</th>
<th>Barcode</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php
include_once 'database.php';
$pdo = Database::connect();
$sql = 'SELECT * FROM product ORDER BY id DESC';
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['category_id'] . '</td>';
echo '<td>'. $row['brand'] . '</td>';
echo '<td>'. $row['name'] . '</td>';
echo '<td>'. $row['barcode'] . '</td>';
echo '<td>'. $row['price'] . '</td>';
echo '<td width=250>';
echo '<a class="btn" href="read.php?id='.$row['id'].'">Read</a>';
echo ' ';
echo '<a class="btn btn-success" href="update.php?id='.$row['id'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="delete.php?id='.$row['id'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<div class="container">
<div class="row">
<h3>PHP CRUD Grid</h3>
</div>
<div class="row">
<p>
Create
</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>CategoryId</th>
<th>Category Name</th>
</tr>
</thead>
include_once 'database.php';
<?php
$sql2 = 'SELECT * FROM category ORDER BY id DESC';
foreach ($pdo->query($sql2) as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['category_name'] . '</td>';
echo '<td width=250>';
echo '<a class="btn" href="readCategory.php?id='.$row['id'].'">Read</a>';
echo ' ';
echo '<a class="btn btn-success" href="updateCategory.php?id='.$row['id'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="deleteCategory.php?id='.$row['id'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
Database::disconnect();
?>
</tbody>
</table>
</div>
</div>
</body>
</html>
Remove the second:
include 'database.php';
or use:
include_once 'database.php';
to prevent double loading of your database file.
You might want to consider not disconnecting and connecting again
You have 6 th elements in the header and 7 td elements in your rows. Try to add a th in the header row.
This implies that the SQL query is failing (PDO returns false if the query fails). The manpage says
If you do not fetch all of the data in a result set before issuing your next call to PDO::query(), your call may fail. Call PDOStatement::closeCursor() to release the database resources associated with the PDOStatement object before issuing your next call to PDO::query().
Edit:
Doesn't look like this is the issue - try adding
echo '<pre>'.print_r($pdo->errorInfo(), true).'</pre>';
after the for each loop, this should output the PDO error details.
I have an HTML table being displayed from php data and I'm trying to move data from one table to another based on what is clicked. I cannot get it to move from table to another but I"m not getting any code error.
<html>
<head>
<title>View Requests</title>
</head>
<body>
<div class="breadcrumbs">
<center>
Home · Requests
</center>
</div>
<?php
require_once '../../scripts/app_config.php';
require_once '../../scripts/database_connection.php';
// get results from database
$result = mysql_query("SELECT * FROM temp")
or die(mysql_error());
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th>Username</th> <th></th> <th></th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['User_id'] . '</td>';
echo '<td>' . $row['First_name'] . '</td>';
echo '<td>' . $row['Last_name'] . '</td>';
echo '<td>' . $row['Username'] . '</td>';
echo '<td>Approve</td>';
echo '<td>Delete</td>';
echo "</tr>";
}
// close table>
echo "</table>";
?>
</body>
</html>
PHP EDIT SCRIPT:
<html>
<head>
<title>View Requests</title>
</head>
<body>
<div class="breadcrumbs">
<center>
Home · Requests · All Users
</center>
<?php
require_once '../../scripts/app_config.php';
require_once '../../scripts/database_connection.php';
$id = $_GET['id'];
$sql = ("INSERT INTO users
SELECT * FROM temp WHERE User_id = $id ");
mysql_query($sql)
or die(mysql_error());
?>
</body>
</html>
I needed to use
$id = $_get['id];
and in the insert statement i had to replace id with User_id
<html>
<head>
<title>View Requests</title>
</head>
<body>
<div class="breadcrumbs">
<center>
Home · Requests · All Users
</center>
<?php
require_once '../../scripts/app_config.php';
require_once '../../scripts/database_connection.php';
$id = $_GET['id'];
$sql = ("INSERT INTO users
SELECT * FROM temp WHERE User_id = $id ");
mysql_query($sql)
or die(mysql_error());
?>
</body>
</html>