I want to turn my table into a datatable so that user can read data displayed more easily and the I could add live filters to select only some type of datas. This is my code, I already wrote the code needed to make it possible.
Despite all, if the code is ran, the table isn't dinamic and doesn't turn into a datatable.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FILTRARE PER GENE</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</head>
<body>
<div>
<div id="holder">
<h1><?php echo "FILTRO PER GENE DELLE VARIANTI";?></h1></div>
<hr />
<br>
<div id="sidebar" style="width:50%">
NUOVA RICERCA
  |
DATI UTENTE
  |
HOME
<P> </P>
</div>
<input type="text" id="search" placeholder="Live Search...">
<BR>
<form action="filtro_per_gene_selezione_per_var_RICERCA_PAZ.php" method="POST">
GENE <select name="gene">
<option></option>
<option>CFH</option>
<option>CD46</option>
<option>CFI</option>
<option>CFB</option>
<option>C3</option>
<option>ADAMTS13</option>
<option>THBD</option>
<option>DGKE</option>
<input type='submit' name='vai' value'Invia'>
</form><BR /><BR />
<div class="container">
<div class="row">
<div class="col-mid-8 col-mid-offset-2">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td width="9%"><b>RISULTATO</b></td>
<td width="9%"><b>dnaCode</b></td>
<td width="9%"><b>Chr</b></td>
<td width="9%"><b>Start</b></td>
<td width="9%"><b>End</b></td>
<td width="5%"><b>Alt</b></td>
<td width="5%"><b>Ref</b></td>
<td width="9%"><b>Zigosity</b></td>
<td width="9%"><b>Gene</b></td>
<td width="9%"><b>Func</b></td>
<td width="9%"><b>Gene Context</b></td>
<td width="9%"><b>Dist</b></td>
</tr>
</thead>
<tbody>
<?php
$conn= mysql_connect("local", "user", "pass");
if (!$conn)
{
die("Connessione non riuscita <br>" . mysql_error());
//}else{
//echo "Connessione al database stabilita con successo<br><br>";
}
mysql_select_db("database_var", $conn);
if(isset($_POST["vai"])){
$dna=$_POST["dna"];
}
$sql="SELECT V.dnaCode, V.Chr, V.Start, V.End, V.Alt, V.Ref, V.zygosity, A.gene, A.Func, A.GeneContext, A.Dist FROM variante as V JOIN annotazioni as A ON V.Start = A.Start AND V.Alt=A.Alt AND V.Ref=A.Ref WHERE V.dnaCode='" .$dna. "'";
$result_gene = mysql_query($sql, $conn) or die(mysql_error());
$record_gene=mysql_fetch_array($result_gene);
$index=1;
while ($record_gene=mysql_fetch_array($result_gene)){
echo '
<tr>
<b><td>'.$index.'</td></b>
<td>'.$record_gene['dnaCode'].'</td>
<td>'.$record_gene['Chr'].'</td>
<td>'.$record_gene['Start'].'</td>
<td>'.$record_gene['End'].'</td>
<td>'.$record_gene['Alt'].'</td>
<td>'.$record_gene['Ref'].'</td>
<td>'.$record_gene['zygosity'].'</td>
<td>'.$record_gene['gene'].'</td>
<td>'.$record_gene['Func'].'></td>
<td>'.$record_gene['GeneContext'].'</td>
<td>'.$record_gene['Dist'].'</td>
</tr>
';
++$index;
};
?>
</tbody>
</table>
</div>
</div>
</div>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
<script type="text/javascript" src="file:///C|/xampp/htdocs/DB/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="file:///C|/xampp/htdocs/DB/js/dataTables.bootstrap.min.js"></script>
<script>
$(document).ready(function(){
$('.table').DataTable();
});
</script>
</body>
</html>
Related
How to make jQuery datatables collapse/expand option with mysql php
I don't want to go for ajax option because in view source fetch.php page can see data
I dont have idea to secure that. when someone that php page open can read all data. so go other method.
But somebody help me to make collapse/expand
$(document).ready(function(){
$('#employee_data').DataTable();
});
<?php
$connect = mysqli_connect("localhost", "root", "", "testing");
$query ="SELECT * FROM tbl_employee ORDER BY ID DESC";
$result = mysqli_query($connect, $query);
?>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
</head>
<body>
<br /><br />
<div class="container">
<h3 align="center">Datatables Jquery Plugin with Php MySql and Bootstrap</h3>
<br />
<div class="table-responsive">
<table id="employee_data" class="table table-striped table-bordered">
<thead>
<tr>
<td>Name</td>
<td>Address</td>
<td>Gender</td>
<td>Designation</td>
<td>Age</td>
</tr>
</thead>
<?php
while($row = mysqli_fetch_array($result))
{
echo '
<tr>
<td>'.$row["name"].'</td>
<td>'.$row["address"].'</td>
<td>'.$row["gender"].'</td>
<td>'.$row["designation"].'</td>
<td>'.$row["age"].'</td>
</tr>
';
}
?>
</table>
</div>
</div>
</body>
</html>
I have created a sales-form in which the date and place of sale of products are selected:
After clicking on the "Szukaj" button, which means "search" or "filter"
the data from the database is extracted using PHP and MSQL queries. After the results of sale are displayed
I want to use the jQuery DATATABLES plug-in to export the data to EXCEL, PDF, etc. The problem is that it does not work and it only copies and exports the first line
Why?here is the admin.php file in which the sale is displayed with a script at the bottom that runs datatable:
<?php
session_start();
if (!isset($_SESSION['zalogowany']))
{
header('Location: index.php');
exit();
}
$connect = new PDO("mysql:host=localhost;dbname=bukowski2", "root", "");
function fill_unit_select_box2($connect)
{
$output = '';
$query = "SELECT * FROM users WHERE user_id!=7";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
$output .= '<option value="'.$row["user"].'">'.$row["user"].'</option>';
}
return $output;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="jquery-3.5.1.min.js" a></script>
<script src="https://kit.fontawesome.com/b99e675b6e.js"></script>
<script src="js2.js" async></script>
<link rel="stylesheet" href="bootstrap.min.css" />
<script src="jquery-ui.js" defer></script>
<link rel="stylesheet" href="style2.css">
<link rel="stylesheet" href="jquery-ui.css"/>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.6.2/css/buttons.dataTables.min.css">
<script src="buttons\datatables.min.js" defer></script>
<script src="buttons\dataTables.buttons.min.js" defer></script>
<script src="buttons\buttons.flash.min.js" defer></script>
<script src="buttons\jszip.min.js" defer></script>
<script src="buttons\pdfmake.min.js" defer></script>
<script src="buttons\buttons.print.min.js" defer></script>
<script src="buttons\buttons.html5.min.js" defer></script>
<script src="buttons\vfs_fonts.js" defer></script>
<script src="buttons\js.js" defer></script>
</head>
<body>
<?php
$_SESSION['sales_date']=date('Y-m-d');
echo '<p class="logged">Zalogowany: '.$_SESSION['user'].' | '.$_SESSION['sales_date'].' | [ Wyloguj się ]</p>';
?>
<div class="wrapper">
<div class="tabs">
<ul>
<li class="active">
<span class="text">TABELA</span>
</li>
<li>
<span class="text">DODAJ/USUŃ</span>
</li>
<li>
<span class="text">3</span>
</li>
<li>
<span class="text">4</span>
</li>
</ul>
</div>
<div class="content">
<div class="tab_wrap" style="display: block;">
<div class="title"></div>
<div class="tab_content">
<div class="container" style="width:100%;">
<h3 align="center">Wyszukiwanie danych sprzedaży</h3><br /> <br /> <br />
<div class="col-md-3" style="float:left;">
<input type="text" name="date" id="date" class="form-control" placeholder="Wybierz datę" />
</div>
<div class="col-md-3" style="float:left;">
<select required name="item_from" id="item_from" class="form-control item_from"><option value="">
<?php echo fill_unit_select_box2($connect); ?>
</option></select>
</div>
<div class="col-md-5" style="float:left;">
<input type="button" name="filter" id="filter" value="Szukaj" class="btn btn-info" />
</div>
<div style="clear:both"></div>
<br />
<div id="order_table">
<table class="table table-bordered" id="example">
<thead>
<tr>
<th width="30%">Nazwa i kolor produktu</th>
<th width="10%" style="text-align:center">Rozmiar</th>
<th width="10%" style="text-align:center">Cena PLN</th>
<th width="10%" style="text-align:center">KARTA PLN</th>
<th width="10%" style="text-align:center">Inna waluta1</th>
<th width="10%" style="text-align:center">Inna waluta2</th>
<th width="10%" style="text-align:center">Od</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th width="30%">Nazwa i kolor produktu</th>
<th width="10%" style="text-align:center">Rozmiar</th>
<th width="10%" style="text-align:center">Cena PLN</th>
<th width="10%" style="text-align:center">KARTA PLN</th>
<th width="10%" style="text-align:center">Inna waluta1</th>
<th width="10%" style="text-align:center">Inna waluta2</th>
<th width="10%" style="text-align:center">Od</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
<div class="tab_wrap" style="display: none;">
<div class="title"></div>
<div class="tab_content">
<p>CONTENT 2</p>
</div>
</div>
<div class="tab_wrap" style="display: none;">
<div class="title"></div>
<div class="tab_content">
<p>CONTENT 3</p>
</div>
</div>
<div class="tab_wrap" style="display: none;">
<div class="title"></div>
<div class="tab_content">
<p>CONTENT 4</p>
</div>
</div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd'
});
$(function(){
$("#date").datepicker();
});
$('#filter').click(function(){
var date = $('#date').val();
var item_from=$('#item_from').val();
if(date != '')
{
$.ajax({
url:"filter.php",
method:"POST",
data:{date:date,item_from:item_from},
success:function(data)
{
$('#order_table').html(data);
}
});
}
else
{
alert("Please Select Date");
}
});
});
</script>
and below is the filter.php file which uses PHP and a MySQL query to extract data from the database, which I want to export using the DATATABLE plug-in buttons:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="jquery-3.5.1.min.js" a></script>
<script src="https://kit.fontawesome.com/b99e675b6e.js"></script>
<script src="js2.js" async></script>
<link rel="stylesheet" href="bootstrap.min.css" />
<script src="jquery-ui.js" defer></script>
<link rel="stylesheet" href="style2.css">
<link rel="stylesheet" href="jquery-ui.css"/>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.6.2/css/buttons.dataTables.min.css">
<script src="buttons\datatables.min.js" defer></script>
<script src="buttons\dataTables.buttons.min.js" defer></script>
<script src="buttons\buttons.flash.min.js" defer></script>
<script src="buttons\jszip.min.js" defer></script>
<script src="buttons\pdfmake.min.js" defer></script>
<script src="buttons\buttons.print.min.js" defer></script>
<script src="buttons\buttons.html5.min.js" defer></script>
<script src="buttons\vfs_fonts.js" defer></script>
<script src="buttons\js.js" defer></script>
</head>
<body>
<?php
//filter.php
if(isset($_POST["date"])) {
//ustanawiamy połącznie z bazą danych
$connect = mysqli_connect("localhost", "root", "", "bukowski2");
if($_POST["item_from"]==""){
$query = "SELECT item_name.item_name,sizes.sizes,sales_table.total_pln,sales_table.total_cart_payment,sales_table.total_oc1,currencies.currency,users.user FROM item_name,sales_table,sizes,currencies,users WHERE sizes.size_id=sales_table.size_id AND item_name.id=sales_table.item_name_color AND currencies.id=sales_table.total_oc2 AND users.user_id=sales_table.user_id AND sales_date='".$_POST["date"]."' ORDER BY sales_id";
}else{
$query0="SELECT user_id FROM users WHERE user='".$_POST["item_from"]."'";
$result = mysqli_query($connect, $query0);
while($row = mysqli_fetch_assoc($result))
{
$e= $row['user_id']."<br>";
}
$user_id = (int)$e;
$query = "SELECT item_name.item_name,sizes.sizes,sales_table.total_pln,sales_table.total_cart_payment,sales_table.total_oc1,currencies.currency,users.user FROM item_name,sales_table,sizes,currencies,users WHERE sizes.size_id=sales_table.size_id AND item_name.id=sales_table.item_name_color AND currencies.id=sales_table.total_oc2 AND users.user_id=sales_table.user_id AND sales_date='".$_POST["date"]."' AND sales_table.user_id=".$user_id." ORDER BY sales_id";
}
$output='';
$result = mysqli_query($connect, $query);
$output .= '
<table class="table table-bordered" id="example">
<thead>
<tr>
<th width="30%">Nazwa i kolor produktu</th>
<th width="10%" style="text-align: center">Rozmiar</th>
<th width="10%" style="text-align: center">Cena PLN</th>
<th width="10%" style="text-align: center">KARTA PLN</th>
<th width="10%" style="text-align: center">Inna waluta1</th>
<th width="10%" style="text-align: center">Inna waluta2</th>
<th width="10%" style="text-align: center">Od</th>
</tr>
</thead>
';
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output .= '
<tbody>
<tr>
<td>'. $row["item_name"] .'</td>
<td style="text-align: center">'. $row["sizes"] .'</td>
<td style="text-align: center">'. $row["total_pln"] .'</td>
<td style="text-align: center">'. $row["total_cart_payment"] .'</td>
<td style="text-align: center">'. $row["total_oc1"] .'</td>
<td style="text-align: center">'. $row["currency"] .'</td>
<td style="text-align: center">'. $row["user"] .'</td>
</tr>
</tbody>
';
}
}
else
{
$output .= '
<tr>
<td colspan="5">Brak danych</td>
</tr>
';
}
$output .= '</table>';
echo $output;
//zamykamy połączenie z bazą danych
mysqli_close($connect);
}
?>
</body>
The js code to initialize the table has been included in the buttons\js.js script file. Here is the code:
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
'copy',
'csv',
'excel',
'pdf',
'print'
]
} );
} );
ok i solved. It was enough to remove the tag from the loop that printed the results because the tag was inserted each time a row of data was inserted. Closed
Currently, I am working on my datatable to display the detail from the database. I am using the php myadmin for the database. But it only manage to display the detail only but not the pagination, sorting and searching is not working. I have followed some other tutorials but it still doesn't work.
<?php
$conn = mysqli_connect("localhost", "root", "", "jiaen");
$sql = "SELECT * FROM stock LEFT OUTER JOIN category ON stock.categoryid=category.categoryid order by stockCode";
//Execute connection
$result = mysqli_query($conn,$sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>Webslesson Tutorial | Datatables Jquery Plugin with Php MySql and Bootstrap</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
</script>
</head>
<body>
<br /><br />
<div class="container">
<h3 align="center">Datatables Jquery Plugin with Php MySql and Bootstrap</h3>
<br />
<div class="table-responsive">
<table id="stock" class="table table-striped table-bordered" >
<thead>
<tr>
<td>Stock Code</td>
<td>Stock Name</td>
<td>Stock Category</td>
<td>Quantity</td>
<td>Price (RM)</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_array($result))
{
echo '
<tr>
<td>'.$row["stockCode"].'</td>
<td>'.$row["stockName"].'</td>
<td>'.$row["categoryName"].'</td>
<td>'.$row["quantity"].'</td>
<td>'.$row["price"].'</td>
<td>Stock In</td>
<td>R&D</td>
<td>Remark Stock</td>
<td>Modify</td>
<td>Delete</td>
</tr>
';
}
?>
</tbody>
</table>
</div>
</div>
//Javascript part for datatable
<script>
$(document).ready(function() {
$('#stock').DataTable();
} );
</script>
</body>
</html>
Your <thead> contains a <tr> which is full of <td> tags instead of <th> tags.
It has 6 tags, so your table will have 6 columns.
Your <tbody> on the other hand has 10 <td> tags inside each <tr> tag.
10 will not fit into 6.
I want to update record in php using GET method but whenever i click on "update button" it does not change anything and just refresh the page.and data remains the same.Here are the codes. Kindly tell me where i m doing it wrong. Thanks
<?php
include_once"dbconfig.php";
if(isset($_GET['edit']))
{
$id=$_GET['edit'];
echo $id;
$sql_query="SELECT * FROM users WHERE user_id='$id' ";
$result_set=mysql_query($sql_query);
$fetched_row=mysql_fetch_array($result_set);
}
if(isset($_POST['btn-update']))
{
// variables for input data
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$city_name=$_POST['city_name'];
//sql query to update into database
$sql_query="UPDATE users SET first_name='$first_name',last_name='$last_name',user_city='$city_name' WHERE user_id='$id' ";
mysql_query($sql_query);
//if(!$sql_query)
//die('data can not update'.mysql_error());
//else
//echo 'data updated successfully';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>
<form method="post">
<table align="center">
<tr>
<td><input type="text" name="first_name" placeholder="First Name" value="<?php echo $fetched_row['first_name']; ?>"required /> </td>
</tr>
<tr>
<td><input type="text" name="last_name" placeholder="Last Name" value="<?php echo $fetched_row['last_name']; ?>" required /> </td>
</tr>
<tr>
<td><input type="text" name="city_name" placeholder="City" value="<?php echo $fetched_row['user_city']; ?>" required /> </td>
</tr>
<tr>
<td>
<button type="submit" name="btn-update"><strong>UPDATE</strong></button>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
Second File
<?php
include_once"dbconfig.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>CRUD Operations With php and MySql </title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<center>
<div id="body">
<div id="content">
<table align="center">
<table align="center">
<tr>
<th colspan="9">Add data Here ! </th>
</tr>
<tr>
<th colspan="2">FirstName </th>
<th colspan="8">LastName</th>
<th colspan="4">CityName </th>
<th>Operations</th>
<!--<th colspan="2">Operations</th> -->
</tr>
<?php
$sql_query="SELECT * FROM users";
$result_set=mysql_query($sql_query);
while($row=mysql_fetch_row($result_set))
{
?>
<tr>
<td><?php echo $row[0]; ?> </td>
<td colspan="4"><?php echo $row[1]; ?></td>
<td colspan="6"><?php echo $row[2];?></td>
<td colspan="4"><?php echo $row[3];?></td>
<td> <a href='edit_data.php?edit=$row[0]'>EDIT</a> </td>
<!--<td align="center"><a href="javascript edt_id('<//?php echo $row[0]; ?><img src="b_edit.png" align="EDIT" /></a></td>
<td align="center"><a href="javascript:delete_id('<//?php echo $row[0];?><img src="b_drop.png" align="DELETE" /></a></td>
</tr> -->
<?php
}
?>
</table>
</div>
</div>
</center>
</body>
</html>
Change
mysql_query($sql_query);
To
mysql_query($sql_query) or die (mysql_error()) ;
You're not sending the id (the form action property is missing
I have created a page where data of the examination and the description displays from database to webpage (page name is manageexam.php)
Code is as follows :
manageexam.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin | Manage Exam</title>
<link rel="stylesheet" type="text/css" href="style1.css">
<style>
.active3{
color:#900;
}
</style>
</head>
<body>
<?php include"livetime.php";?>
<table class="table">
<tr>
<th class="th" align="left" colspan="2" >
<?php
session_start();
if($_SESSION['username'])
echo "<span id='welcome'>Congratulation, <span id='company'> ".$_SESSION['username']."</span> you are logged in!</span>";
else
die("You Must be logged in!");
?>
<span class="clock"><span id="clockbox"></span></span></th>
</tr>
<tr>
<td valign="top" class="tdleft"><br>
<span class="message">Admin Controller</span>
<?php include('menu.php');?>
</td>
<td bgcolor="#FFFFCC" valign="top" style="padding:5px;">
<h2>Manage Exams Available:</h2>
<?php
include('dbconfig.php');
$query = mysql_query("SELECT * FROM examsmeta");
$numrows = mysql_num_rows($query);
echo "<strong>Total Exams Available: $numrows </strong>";
echo "<br>";
echo "<table class='table2'>
<tr>
<th width='30%'>Subject Name</th>
<th width='60%'>Description</th>
<th width='30%'>Select</th>
</tr>
<form action= 'manageexam.php' method='post'>";
while($row = mysql_fetch_array($query))
{
echo "<tr>";
echo "<td>" .$row[1]. "</td>";
echo "<td>" .$row[2]. "</td>";
echo "<td><input name='select' type='checkbox' value=".$row[1]."></td>";
echo "</tr>";
}
echo "</table><br>";
echo "<input class='bttn' type='submit' value='Delete Exam' name='delete'>";
echo " <input class='bttn' type='submit' value='Edit Exam' name='edit' > ";
echo "</form>"
?>
</td>
</tr>
<tr>
<td class="td" colspan="2" height="10%">
Status Bar:
<span id="black">
<?php
if(!isset($_REQUEST['logout']))
{
include('delete.php');
if(isset($_POST['edit'])){
header('location:editexam.php?id='.$_POST['select']);
}
}
else
{
echo $_REQUEST['logout'];
}
?>
</span>
<span class="logout">LOGOUT</span>
</td>
</tr>
</table>
</body>
</html>
Now at this page i have added checkbox in front of each exam and two buttons, One is for Delete exams Permanently and second is for Edit exam. At Editing Exam Whenever i choose any 1 exam (via checkbox) and click on edit Following result displays(shown example of choosing exam commerce) :
Unknown column 'Commerce' in 'where clause'
Code of editexam.php is as follows :
<?php
include('dbconfig.php');
if(isset($_REQUEST['id'])){
if($_REQUEST['id']=='')
{
header('location:manageexam.php?message2=Error: Please select a Value!');
}
else{
$id=$_REQUEST['id'];
$query="select * from examsmeta where SubId=".$id;
$res=mysql_query($query) or die(mysql_error());
$row=mysql_fetch_assoc($res);
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin |Edit Exam</title>
<link rel="stylesheet" type="text/css" href="style1.css">
<link rel="stylesheet" type="text/css" href="datepickr.css" />
<style>
.active5{
color:#900;}
</style>
</head>
<body>
<!--text editor.-->
<script type="text/javascript" src="tinymce/tinymce.min.js"></script>
<script type="text/javascript">tinymce.init({
selector: "textarea",
// ===========================================
// INCLUDE THE PLUGIN
// ===========================================
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste jbimages"
],
// ===========================================
// PUT PLUGIN'S BUTTON on the toolbar
// ===========================================
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image jbimages",
// ===========================================
// SET RELATIVE_URLS to FALSE (This is required for images to display properly)
// ===========================================
relative_urls: false
});</script>
<!--text editor script close-->
<?php include('livetime.php');?>
<table width="100%" class="table">
<tr>
<th class="th" align="left" colspan="2" >
<?php
session_start();
if($_SESSION['username'])
echo "<span id='welcome'>Congratulation, <span id='company'> ".$_SESSION['username']."</span> you are logged in!</span>";
else
die("You Must be logged in!");
?>
<span class="clock"><span id="clockbox"></span></span></th>
</tr>
<tr>
<td valign="top" class="tdleft"><br>
<span class="message"> Admin Controller</span>
<?php include('menu.php');?>
</td>
<td bgcolor="#FFFFCC" valign="top" style="padding:5px;">
<h2>Edit Exams Available </h2>
<form id="regform" action="" method="post">
<div class="wrapper">
<strong>Subject Name: </strong>
<div class="bg">
<input class="input" type="text" value="<?php if(isset($_REQUEST['id'])){
echo $row['name'];
}
?>" name="name"/>
</div>
</div>
<div class="wrapper">
<strong>Description:</strong>
<div class="bg">
<textarea class="textbox" name="description">
<?php if(isset($_REQUEST['id']))
{
echo $row['description'];
} ?>
</textarea>
<input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>" />
</div>
</div>
<br>
<div class="bttnalign"><a href="editexam.php?id=0"><input class="bttn" type="button" value="Clear">
<input class="bttn" type="submit" name="submit" value="Update"/>
</a>
</div>
</form>
</td>
</tr>
<tr>
<td class="td" colspan="2" height="10%">
Status Bar:
<span id="black">
<?php
if(isset($_POST['submit']))
{
$na=$_POST['name'];
$nad=$_POST['description'];
$rid=$_POST['id'];
$nupdate=mysql_query("UPDATE examsmeta SET Name='".$na."',Description='".$nad."' WHERE SubId='".$rid."'") or die(mysql_error());
header("location:manageexam.php?message2=Data Updated Successfully!");
}
?>
</span>
<span class="logout">LOGOUT</span>
</td>
</tr>
</table>
<!--Date Picker-->
<script type="text/javascript" src="datepickr.min.js"></script>
<script type="text/javascript">
new datepickr('datepick', {
'dateFormat': 'm/d/Y'
});
</script>
<!--Date Picker closed-->
</body>
</html>
What am i doing wrong, anyone explain please?
You are passing $row[1] as parameter which I assume that is the column with the name.
Change the code below:
echo "<td><input name='select' type='checkbox' value=".$row[1]."></td>";
to
echo "<td><input name='select' type='checkbox' value=".$row[0]."></td>";
This will pass the id by parameter, (I am assuming that the id column is in the 0 position)/