Editing value is not working Properly in php - php

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)/

Related

Turn a table into a data table

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
&nbsp |
DATI UTENTE
&nbsp |
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>

How do I echo more than one product dynamically on the same invoice page

I am trying to echo more than one item on an invoice for the same customer. I am able to echo them from the database, but instead of each item being echoed on the same invoice (on different rows), it echoes the full invoice 2 times (or more depending on how many items are on the invoice) with each item on each invoice. Below is my code (I have not yet cleaned the code up. I am leaving that step once the code works).
<?php include "database_connection.php" ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>DPB quote</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="css/bootstrap.min.css"><!--erase this link once the app is completed-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel='stylesheet' type='text/css' href='css/style2.css' />
<link rel='stylesheet' type='text/css' href='css/print.css' media="print" />
<script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='js/example.js'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css"><!--search pagination and delete reference link-->
<script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script><!--search pagination and delete reference link-->
</head>
<body>
<?php
$statement = $connect->prepare("
SELECT * FROM tbl_order
WHERE order_id = :order_id
LIMIT 1
");
$statement->execute(
array(
':order_id' => $_GET["id"]
)
);
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<script>
$(document).ready(function(){
$('#order_no').val("<?php echo $row["order_no"]; ?>");
$('#order_date').val("<?php echo $row["order_date"]; ?>");
$('#order_receiver_name').val("<?php echo $row["order_receiver_name"]; ?>");
$('#address_line_1').val("<?php echo $row["address_line_1"]; ?>");
$('#address_line_2').val("<?php echo $row["address_line_2"]; ?>");
$('#city').val("<?php echo $row["city"]; ?>");
$('#state').val("<?php echo $row["state"]; ?>");
$('#zip_code').val("<?php echo $row["zip_code"]; ?>");
$('#phone_number').val("<?php echo $row["phone_number"]; ?>");
$('#email').val("<?php echo $row["email"]; ?>");
$('#notes').val("<?php echo $row["notes"]; ?>");
});
</script>
<form method="post" id="invoice_form">
<div class="container">
<?php
$statement = $connect->prepare("
SELECT * FROM tbl_order_item
WHERE order_id = :order_id
");
$statement->execute(
array(
':order_id' => $_GET["id"]
)
);
$item_result = $statement->fetchAll();
$m = 0;
foreach($item_result as $sub_row)
{
$m = $m + 1;
?>
<!--QUOTATION APP 2 STARTS HERE-->
<div id="page-wrap">
<textarea id="header">Quotation</textarea>
<div id="identity">
<textarea id="address">Discount Plastic Bags
7750
Suite
Irving
Phone: </textarea>
<div id="logo">
<div id="logohelp">
(max width: 540px, max height: 300px)
</div>
<img id="image" src="images/dpblogo3.png" alt="logo" />
</div>
</div>
<div style="clear:both"></div>
<div id="customer">
<!--<form id="quote_date" class="" action="index.php" method="post">-->
<tr>
<td><textarea placeholder="Enter Customer Information" id="address" name="company_info"></textarea></td>
</tr>
<table id="meta">
<tr>
<td class="meta-head">Invoice #</td>
<td><textarea>000123</textarea></td>
</tr>
<tr>
<td class="meta-head">Date</td>
<td><textarea placeholder="enter quotation date" name="quote_date"></textarea></td>
</tr>
<tr>
<td class="meta-head">Amount Due</td>
<td><textarea placeholder="enter amount due" name="amount_due"></textarea></td>
</tr>
</table>
</div>
<table id="items">
<tr>
<th>SKU</th>
<th>Description</th>
<th>Quantity</th>
<th>Unit Cost</th>
<th>Price</th>
</tr>
<tr class="item-row">
<!--<td><span id="sr_no"><?php //echo $m; ?></span></td>-->
<td><input type="text" name="sku[]" id="sku<?php echo $m; ?>" class="item-name" value="<?php echo $sub_row["sku"]; ?>" /></td>
<td><input type="text" name="item_name[]" id="item_name<?php echo $m; ?>" class="description" value="<?php echo $sub_row["item_name"]; ?>" /></td>
<td><input type="text" name="order_item_quantity[]" id="order_item_quantity<?php echo $m; ?>" data-srno="<?php echo $m; ?>" class="qty" value = "<?php echo $sub_row["order_item_quantity"]; ?>" /></td>
<td><input type="text" name="order_item_price[]" id="order_item_price<?php echo $m; ?>" data-srno="<?php echo $m; ?>" class="cost" value="<?php echo $sub_row["order_item_price"]; ?>" /></td>
<td><input type="text" name="order_item_final_amount[]" id="order_item_final_amount<?php echo $m; ?>" data-srno="<?php echo $m; ?>" readonly class="price" value="<?php echo $sub_row["order_item_final_amount"]; ?>" /></td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Subtotal</td>
<td class="total-value"><textarea id="subtotal" name="subtotal"></textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Total</td>
<td class="total-value"><textarea name="total" id="total"></textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="total-line">Amount Paid</td>
<td class="total-value"><textarea id="paid">$0.00</textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="total-line balance">Balance Due</td>
<td class="total-value balance"><textarea name="balance_due" class="due"> </textarea></td>
</tr>
</table>
<div id="terms">
<h5>Notes</h5>
<textarea name="notes" placeholder="enter quotation notes" rows="12" style="font-size: 15pt"></textarea>
</div>
</div>
</form>
</body>
</html>
<?php
}
}
?>
I would do something like this. This is not tested and just an example of how I do it. There are a few other ways but this works best for me
// other needed code above
$results = sqlsrv_query($link, $query);
//query returns one value for these
echo "<table>";
echo "<tr> ";
echo "<td>".$name."</td>";
echo "<td>".$store."</td>";
echo "</tr>";
//start your multiple items row
while($row=sqlsrv_fetch_array($results))
{
$items = $row['items'];
echo "<tr> ";
echo "<td>".$items."</td> ";
echo "</tr>";
}
echo "<tr> ";
echo "<td>".$cost."</td>";
echo "<td>".$other."</td>";
echo "</tr>";
echo "</table> ";
//other code for the rest of the page below
Result would be:
Bob Bob's Store
ITEM
ITEM
ITEM
$50.00 other

How to update form in PHP

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

Form Data to a Table With a Database

A few months ago I was working on a project and posted it here for help: How to submit a form results to a table on another page?. Now I need help again. If you go down to this comment on my previous question (see comment here: How to submit a form results to a table on another page?), this user was helping me and I got everything figured out except the the database. When I submit my form, the page loads with a blank table. How can I get it so when I enter the form information and submit it, it then goes to the 2nd page (see below) and puts the data into the table? I had it working before, before I incorporated the database in it.
Here is my code for the page called dispatch.php (which is the the form page):
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LMCS CAD - Live Incident Status</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="http://tabstart.com/system/icons/14476/original/favicon.ico?1306467370" />
<meta name="robots" content="noindex">
</head>
<body style="font-family: Arial, Sans-Serif; font-size: 12px;">
<div align="center">
<h1><img src="assests/lmcslogo.png" alt="York County 911 - Live Incident Status"/></h1>
<p>
<script type="text/javascript">
document.write(Date());
</script></p>
<h1>Home | Dispatch An Incident | Help</h1>
<div></div>
</div>
<div align="center">
<form id="dispatch" name="dispatch" method="post" action="indexcad.php">
<table width="801" height="420" border="1">
<tr>
<td align="center" id="town">TOWN</td>
<td><input type="text" name="town" id="town" /></td>
</tr>
<tr>
<td align="center" id="location">LOCATION</td>
<td><input type="text" name="location" id="location" /></td>
</tr>
<tr>
<td align="center" id="incident_type">INCIDENT TYPE</td>
<td><input type="text" name="incident_type" id="incident_type" /></td>
</tr>
<tr>
<td align="center" id="time_date">TIME/DATE</td>
<td><input name="time_date" type="text" id="time_date" maxlength="60" /></td>
</tr>
<tr>
<td width="138" align="center"><p id="admin">ADMIN </p></td>
<td width="228"><input name="admin" type="text" id="admin" size="4" maxlength="4" /></td>
</tr>
</table>
<p>
<input type="submit" name="button" id="button" value="Submit" />
<input type="reset" name="button2" id="button2" value="Reset" />
</p>
</form>
</div>
<p> </p>
<hr />
<p style="text-align:center; font-size: 12px;">© 2014 Lake McHenry County Scanner</p>
</body>
</html>
And here is my page called indexcad.php (which is the page the form data comes up on):
<!DOCTYPE html>
<html>
<?php
//because you use method post you can access your form value by using this code
$town = $_POST['town'];
$location = $_POST['location'];
$incident_type= $_POST['incident_type'];
$time_date= $_POST['time_date'];
$admin = $_POST['admin'];
$db = mysql_connect('localhost','root','') or die("Database error");
mysql_select_db('mydatabase', $db);
$result= mysql_query("select * from cad");
while($row = mysql_fetch_array($result))
?>
<head>
<title>LMCS CAD</title>
</head>
<body>
<div align="center">
<form action="" method="get">
<table width="968" height="248" border="1" align="center" cellpadding="10" cellspacing="0" rules="rows" id="incidents" style="color:#333333;border-collapse:collapse;text-align:left;">
<tr style="color:White;background-color:#5D7B9D;font-weight:bold;font-style:italic;">
<th scope="col">TOWN</th>
<th scope="col">LOCATION</th>
<th scope="col">INCIDENT TYPE</th>
<th scope="col">TIME/DATE</th>
<th scope="col">ADMIN</th>
</tr>
<tr style="color:#333333;background-color:#F7F6F3;font-weight:bold;">
<?php
//replace this to your old php code
echo "<td>" .$row['town'] ."</td>";
echo "<td>" .$row['location'] ."</td>";
echo "<td>" .$row['incident_type'] ."</td>";
echo "<td>" .$row['time_date'] ."</td>";
echo "<td>" .$row['admin'] ."</td>";
?>
</tr>
</table>
</form>
</body>
</html>
The general shape of your script could look like this (i didn't look precisely if smthg wrong in your code, just reorganized it a bit...
<!DOCTYPE html>
<html>
<head>
<title>LMCS CAD</title>
</head>
<body>
<div align="center">
<form action="" method="get">
<table width="968" height="248" border="1" align="center" cellpadding="10" cellspacing="0" rules="rows" id="incidents" style="color:#333333;border-collapse:collapse;text-align:left;">
<tr style="color:White;background-color:#5D7B9D;font-weight:bold;font-style:italic;">
<th scope="col">TOWN</th>
<th scope="col">LOCATION</th>
<th scope="col">INCIDENT TYPE</th>
<th scope="col">TIME/DATE</th>
<th scope="col">ADMIN</th>
</tr>
<tr style="color:#333333;background-color:#F7F6F3;font-weight:bold;">
<?php
$town = $_POST['town'];
$location = $_POST['location'];
$incident_type= $_POST['incident_type'];
$time_date= $_POST['time_date'];
$admin = $_POST['admin'];
$db = mysqli_connect('localhost','root','') or die("Database error");
mysqli_select_db($db, 'mydatabase');
$result= mysqli_query($db, "select * from cad");
while($row = mysqli_fetch_array($result))
{
echo "<td>" .$row['town'] ."</td>";
echo "<td>" .$row['location'] ."</td>";
echo "<td>" .$row['incident_type'] ."</td>";
echo "<td>" .$row['time_date'] ."</td>";
echo "<td>" .$row['admin'] ."</td>";
}
?>
</tr>
</table>
</form>
</body>
</html>

Show database entries after pressing submit button

I have a page where I search for the books that an author wrote (really basic search based on an assignment I had 2 months ago). I choose the author from a dropdown box and after I press the "Submit" button the results should appear.
Here is the page's code:
<?php
include ("includes/connections.php");
if($_POST)
{
if (!isset($_POST["authors"])){
header("Location: searchAuthor.php");
exit;
}
foreach ($_POST["authors"] as $author)
{
?????????
}
}
?>
<?php include ("includes/connections.php");
function dropdown($intIdField, $strfNameField, $strlNameField, $strTableName, $strOrderField, $strNameOrdinal, $strMethod="asc") {
echo "<select name=\"{$strNameOrdinal}[]\">\n";
echo "<option value=\"NULL\">Select Value</option>\n";
$strQuery = "SELECT $intIdField, $strfNameField, $strlNameField
FROM $strTableName
ORDER BY $strOrderField $strMethod";
$rsrcResult = mysql_query($strQuery) or die(mysql_error());
while($arrayRow = mysql_fetch_assoc($rsrcResult)) {
$strA = $arrayRow["$intIdField"];
$strB = $arrayRow["$strlNameField"] . " " . $arrayRow["$strfNameField"];
echo "<option value=\"$strA\">$strB</option>\n";
}
echo "</select>";
}
?>
<!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>Add Book Information</title>
<link href="back.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Search for Books of an Author</h1><table width="528" border="0" align="center">
<tr>
<td width="480"><span id="tip">*Hitting the "Search books of Author" button without filling the fields with an asterisk will just reset the form</span></td>
</tr>
</table>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" id="formBook">
<table width="563" border="0" align="center">
<tr>
<td style="text-align: right"><label for="authors">Select an Author*:</label></td>
<td><?php dropdown("author_ID", "author_firstname", "author_lastname", "author", "author_lastname", "authors"); ?></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Search books of Author" /></td>
</tr>
<tr>
<td><div align="left"><img src="images/buttonleft.png" alt="previous" width="70" height="70" usemap="#Previous" border="0"></div></td>
<td><div align="right"><img src="images/buttonright.png" alt="next" width="70" height="70" usemap="#Next" border="0">
<map name="Previous">
<area shape="circle" coords="35,35,33" href="addSubject.php">
</map>
<map name="Next">
<area shape="circle" coords="35,35,33" href="addEdition.php">
</map>
</div></td>
</tr>
</table>
</form>
</body>
</html>
As you can see I have everything inside a table (convenient for small stuff like this). I want when I press the submit button, the author that was chosen to be inputed in a method which will display the results from the query. The query will be executed in the foreach where the ?????? are. Then I want the result of the query to be used to display inside my table (by adding more rows and inserting one result in each row through a php function) the results.
Is there a way to do that just with php? I don't know how to use Javascript just php and html. Even if I have to insert the result of the query in another page and display everything there I'm ok with that.
I haven't written the query just yet.
Actually the foreach is there to put in a single variable each book the author has written.
Here's an example. Queries/fields are bogus.
<?php
if (isset($_POST['Submit'])) {
$strQuery = "SELECT 'field1', 'field2', 'field3'
FROM $strTableName
ORDER BY $strOrderField $strMethod";
$rsrcResult = mysql_query($strQuery) or die(mysql_error());
?>
<table>
<td> HEADER 1 </td> <td> HEADER 2 </td> <td> HEADER 3 </td>
<?php
while ($row = mysql_fetch_array($rsrcResult) {
echo "<tr><td>".$row['field1']."</td><td>".$row['field2']."</td><td>".$row['field3']."</td>";
}
?>
</table>

Categories