how to avoid duplicate values to print in the html table - php

Order.php:
<?php
require_once('conn.php');
session_start();
$itemId=$_SESSION['itemId'];
$tnumber=$_SESSION['tnumber'];
$custno=$_SESSION['custno'];
$sql="select itemId,subtitle,price,quantity from cart where tnumber='$tnumber'" ;
$sql2="select subtitle from cart where itemId='$itemId'";
$res2=mysqli_query($dbhandle,$sql2);
$row1= mysqli_num_rows($res2);
$res=mysqli_query($dbhandle,$sql);
$total=0;
?>
<html>
<head>
<title>Home</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" type='text/css' href='cartbox.css'/>
</head>
<body>
<h1></h1>
<script src="home.js"></script>
<div id="shopping-cart"> </div>
<?php
echo "<table id='t1' border='1'>
<th>Subtitle</th>
<th>Quantity</th>
<th>Price</th>
<th>Amount</th>
</tr>";
if (row1 > 0) {
while ($row=mysqli_fetch_array($res)) {
$amount=$row['price']*$row['quantity'];
echo "<form id='addform{$row['itemId']}' method='post' action='cartdelete.php'> ";
echo "<tr>";
echo "<td>" .$row['subtitle'] ."</td>";
echo "<td>" .$row['quantity'] ."</td>";
echo "<td>" .$row['price'] ."</td>";
echo "<td>" . $amount . "</td>";
echo "<td><input type='submit' value='x' name='submit'></td>";
echo "<td><input type='text' name='itemId' value= '{$row['itemId']}'></td>";
echo"</form>";
echo "</tr>";
$total = $total+ $amount;
}
}
echo "</table>";
?>
<?php echo $total ?>
<input type="button" name="continue" value="Continue Order" style="position: absolute;top:200px;" onclick="location.href='customerdicecream.php'">
</body>
</html>
I'm trying to display the data in an HTML table (with primary key). I need the subtitle to be entered into the HTML table, only once, but with the if condition I'm not able to achieve it. How can I do that?

You may use DISTINCT / GROUP BY in your query for prevention of the redundant value.
ex.
$sql="select itemId,subtitle,price,quantity from cart where tnumber='$tnumber'" ;
$sql2="select DISTINCT subtitle from cart where itemId='$itemId'";
Reference Site

Define a variable $prevSubTitle before the while ($row=mysqli_fetch_array($res)) { condition.
And when you read value for it from $row['subtitle'], check if it matches with previously read value. If 'false' display new value, else fill td with a space as <td> </td>
#prevSubTitle = '';
while ($row=mysqli_fetch_array($res)) {
$amount=$row['price']*$row['quantity'];
echo "<form id='addform{$row['itemId']}' method='post' action='cartdelete.php'> ";
echo "<tr>";
$subtitle = $row['subtitle'];
if( ! ( $subtitle == $prevSubTitle ) ) {
$prevSubTitle = $subtitle;
}
else {
$subtitle = ' ';
}
echo "<td>" . $subtitle ."</td>"; // empty when matched with previous row title
echo "<td>" .$row['quantity'] ."</td>";
echo "<td>" .$row['price'] ."</td>";

Related

can't figure out how to list all rows from MYSQL in php

So I have finished my page and want to list all the data in my database for the current customer id selected and I can only seem to get the first row in the DB to list, I can't get all of them.
I have tried a while loop but I just can't seem to get the logic. Any help would be appreciated
Here is the entire code for the page. I want to use the last table on the page to show all the customer data.
I have labeled it with a comment if you are looking for the section im referring to.
// Display all data for customer from db. -- cant seem to figure this part out [while loop?]
<?php
// Check existence of id parameter before processing further
if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
// Include config file
require_once "../includes/config.php";
// Prepare a select statement
$sql = "SELECT * FROM customers, orders WHERE customers.id = orders.customerId AND customers.id = ?";
if($stmt = mysqli_prepare($con, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "i", $param_id);
// Set parameters
$param_id = trim($_GET["id"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
// Retrieve individual field value
$customerId = $row['customerId'];
$name = $row['name'];
$address = $row['address'];
$phone = $row['phone'];
$email = $row['email'];
$other1 = $row['other1'];
$other2 = $row['other2'];
$notStartedCheckbox = $row['notStartedCheckbox'];
$dateToWork = $row['dateToWork'];
$finishedCheckbox = $row['finishedCheckbox'];
$dateTimeFinished = $row['dateTimeFinished'];
$paidCheckbox = $row['paidCheckbox'];
$dateTimePaid = $row['dateTimePaid'];
$paidWith = $row['paidWith'];
$notes = $row['notes'];
} else{
// URL doesn't contain valid id parameter. Redirect to error page
header("location: error.php");
exit();
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>View Record</title>
<!-- stylesheets -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- scripts -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://kit.fontawesome.com/16d3fe3a77.js" crossorigin="anonymous"></script>
<style>
.wrapper{
width: 80%;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div>
<h3 class="mt-5 mb-3"><?php echo $row['name'] . ' | ' . $row['address'] . ' | ' . $row['phone'] . ' | ' . $row['email'] . ' ' . $row['other1'] . ' ' . $row['other2'] ; ?></h3>
<!-- Submit a form that adds a new job for a customer -->
<form action="newWorkOrder.php" method="post">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Customer ID (Auto)</th>
<th>Started</th>
<th>Work Date</th>
<th>Service</th>
<th>Finished</th>
<th>Finished Date/Time</th>
<th>Paid</th>
<th>Paid Date/Time</th>
<th>Paid With</th>
<th>Notes</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="radio" checked name="customerId" id="customerId" value="<?php echo $row['customerId'] ?>"></td>
<td><input type="checkbox" name="notStartedCheckbox" id="notStartedCheckbox" value="0"></td>
<td><input type="date" name="dateToWork" id="dateToWork"></td>
<td>
<select name="service" id="service">
<option value="mowing">Mowing</option>
</select>
</td>
<td><input type="checkbox" name="finishedCheckbox" id="finishedCheckbox" value="0"></td>
<td><input type="datetime-local" name="dateTimeFinished" id="dateTimeFinished"></td>
<td><input type="checkbox" name="paidCheckbox" id="paidCheckbox" value="0"></td>
<td><input type="datetime-local" name="dateTimePaid" id="dateTimePaid"></td>
<td><input type="text" name="paidWith" id="paidWith"></td>
<td><input type="text" name="notes" id="notes"></td>
<td><input type="submit" value="submit"></td>
</tr>
</table>
</form>
<hr>
<!-- Display the table -->
<?php
echo "<table class='table table-bordered table-striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>Started</th>";
echo "<th>Work Date</th>";
echo "<th>Service</th>";
echo "<th>Finished</th>";
echo "<th>Finished Date/Time</th>";
echo "<th>Paid</th>";
echo "<th>Paid Date/Time</th>";
echo "<th>Paid With</th>";
echo "<th>Notes</th>";
echo "</tr>";
echo "</thead>";
// Display all data for customer from db. -- cant seem to figure this part out [while loop?]
echo "<tbody>";
echo "<tr>";
echo "<td>" . $row['notStartedCheckbox'] . "</td>";
echo "<td>" . $row['dateToWork'] . "</td>";
echo "<td>" . $row['service'] . "</td>";
echo "<td>" . $row['finishedCheckbox'] . "</td>";
echo "<td>" . $row['dateTimeFinished'] . "</td>";
echo "<td>" . $row['paidCheckbox'] . "</td>";
echo "<td>" . $row['dateTimePaid'] . "</td>";
echo "<td>" . $row['paidWith'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "</tr>";
echo "</table>";
?>
<br>
<p>Back</p>
</div>
</div>
</div>
</div>
</body>
</html>
Here is the section I can't get to work properly, it will display all rows after I submit a new form, but won't show any pre-existing data from my database.
while($row = mysqli_fetch_array($result) ){
echo "<tr>";
if($row['notStartedCheckbox'] == true) {
echo "<td>" . 'Started' . "</td>";
} else {
echo "<td style='color: red'>Not Started</td>";
}
echo "<td>" . $row['dateToWork'] . "</td>";
echo "<td>" . $row['service'] . "</td>";
if($row['finishedCheckbox'] == true) {
echo "<td>" . 'Finished' . "</td>";
} else {
echo "<td style='color: red'>Not Finished</td>";
}
echo "<td>" . $row['dateTimeFinished'] . "</td>";
if($row['paidCheckbox'] == true) {
echo "<td>" . 'Paid' . "</td>";
} else {
echo "<td style='color: red'>Not Paid</td>";
}
echo "<td>" . $row['dateTimePaid'] . "</td>";
echo "<td>" . $row['paidWith'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "</tr>";
}

PHP foreach loop with array table

How do I change it into table form with three headings which are: Company name (ABC and XYZ), Branch (Kuching and Sibu for both companies respectively), and Staff name (for both companies according to the array). I'm a beginner. Please help as I'm stuck. Something's wrong with my code.
<html>
<style>
</style>
<body>
<?php
$v_company= array(
'ABC'=>array('Kuching'=>array('Michael', 'Jenny'),
'Sibu'=>array('Sally', 'Muhammad', 'Mutu')
),
'XYZ'=>array('Kuching'=>array('Lucy', 'Abdullah'),
'Sibu'=>array('John', 'Alicia')
)
);
?>
<table>
<tr><th>Company's Name</th>
<th>Branch</th>
<th>Staff's Name</th>
</tr>
<?php
foreach($v_company as $v_company_name=>$v_company_info){
echo "<tr>";
echo "<td>";
echo "$v_company_name <br>";
echo "</td>";
echo "</tr>";
foreach($v_company_info as $v_branch=>$v_staffs){
echo "<td>";
echo "$v_branch <br/>";
echo "</td>";
foreach($v_staffs as $v_staff){
echo "<td>";
echo "$v_staff <br/>";
echo "</td>";
echo "Company: ". $v_company_name. ",Branch: ". $v_branch. ",Staff: " .$v_staff . "<br>";
}
}
}
?>
</table>
</body>
</html>
You can use this code
<html>
<style>
</style>
<body>
<?php
$v_company= array(
'ABC'=>
array('Kuching'=>array('Michael', 'Jenny'),
'Sibu'=>array('Sally', 'Muhammad', 'Mutu')
),
'XYZ'=>array('Kuching'=>array('Lucy', 'Abdullah'),
'Sibu'=>array('John', 'Alicia')
)
);
?>
<table>
<tr><th>Company's Name</th>
<th>Branch</th>
<th>Staff's Name</th>
</tr>
<?php
$company = '';
$branch = '';
$staff = '';
foreach($v_company as $v_company_name=>$v_company_info){
foreach($v_company_info as $v_branch=>$v_staffs){
foreach($v_staffs as $v_staff){
echo "<tr>";
echo "<td>";
if($company == '' || $company != $v_company_name){
$company = $v_company_name;
echo "$v_company_name <br>";
}
echo "</td>";
echo "<td>";
if($branch != $v_branch){
$branch = $v_branch;
echo "$v_branch <br>";
}
echo "</td>";
echo "<td>";
echo "$v_staff <br/>";
echo "</td>";
echo "</tr>";
}
}
}
?>
</table>
</body>
</html>
You can copy paste if you want. Happy coding
I updated your foreach loop echo value's try this:
<?php
foreach($v_company as $v_company_name=>$v_company_info){
$rowcount = 0;
foreach($v_company_info as $v_branch=>$v_staffs){
echo "<tr>";
echo "<td>";
echo ($rowcount == 0 )? $v_company_name : "";
echo "</td>";
echo "<td>";
echo "$v_branch <br/>";
echo "</td>";
echo "<td>";
foreach($v_staffs as $v_staff){
echo "$v_staff <br/>";
}
echo "</td>";
echo "</tr>";
$rowcount +=1;
}
}
?>
Is this your desired Output?
You can use this to get all the employees in separate rows
<html>
<style>
</style>
<body>
<?php
$v_company= array(
'ABC'=>array('Kuching'=>array('Michael', 'Jenny'),
'Sibu'=>array('Sally', 'Muhammad', 'Mutu')
),
'XYZ'=>array('Kuching'=>array('Lucy', 'Abdullah'),
'Sibu'=>array('John', 'Alicia')
)
);
?>
<table border="1" width="100%">
<tr><th>Company's Name</th>
<th>Branch</th>
<th>Staff's Name</th>
</tr>
<?php
foreach($v_company as $v_company_name=>$v_company_info){
foreach($v_company_info as $v_branch=>$v_staffs){
foreach($v_staffs as $v_staff){
echo "<tr>";
echo "<td>";
echo "$v_company_name";
echo "<td>";
echo "$v_branch <br/>";
echo "</td>";
echo "<td>";
echo "$v_staff <br/>";
echo "</td>";
echo "Company: ". $v_company_name. ",Branch: ". $v_branch. ",Staff: " .$v_staff . "<br>";
echo "</td>";
echo "</tr>";
}
}
}
?>
</table>
</body>
</html>

always the first row of the html table gets deleted using php code

order.php
require_once(conn.php);
session_start();
$itemId=$_SESSION['itemId'];
$tnumber=$_SESSION['tnumber'];
$custno=$_SESSION['custno'];
$sql="select itemId,subtitle,price,quantity from cart where tnumber='$tnumber'" ;
$res=mysqli_query($dbhandle,$sql);
$total=0;
?>
<html>
<head>
<title>Home</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" type='text/css' href='cartbox.css'/>
</head>
<body>
<h1></h1>
<script src="home.js"></script>
<div id="shopping-cart"> </div>
<?php
echo "<table id='t1' border='1'>
<th>Subtitle</th>
<th>Quantity</th>
<th>Price</th>
<th>Amount</th>
</tr>";
while ($row=mysqli_fetch_array($res))
{
$amount=$row['price']*$row['quantity'];
echo "<tr>";
echo "<td>" .$row['subtitle'] ."</td>";
echo "<td>" .$row['quantity'] ."</td>";
echo "<td>" .$row['price'] ."</td>";
echo "<td>" . $amount . "</td>";
echo' <form id="addform" method="post" action="cartdelete.php"> ';
echo "<td><input type='submit' value='x' name='submit'></td>";
echo "<td><input type='text' name='itemId' value= ".$row['itemId']."></td>";
$total = $total+ $amount;
}
echo"</form>";
echo "</table>";
?>
<?php echo $total ?>
<input type="button" name="continue" value="Continue Order" style="position: absolute;top:200px;" onclick="location.href='customerdicecream.php'">
</body>
</html>
cartdelete.php
<?php
require_once(conn.php);
$itemId=(filter_input(\INPUT_POST,'itemId'));
$sql1="select itemId from cart";
$res1=mysqli_query($dbhandle,$sql1);
$row=mysqli_fetch_array($res1);
$itemId1=$row['itemId'];
if(!empty(\filter_input(INPUT_POST,'submit')))
{
$sql="delete from cart where itemId='$itemId1'";
$res=mysqli_query($dbhandle,$sql) or die(\mysqli_error($dbhandle));
}
echo"deleted successfully";
$mysqli_close = \mysqli_close($dbhandle);
i have retrieved the value from cart table and displayed in the html table,each row havhaving a button to delete.But whenever i try to delete irrespective of the button,only the first row of the table gets deleted.I guess the sql query in the deletecart.php is wrong.Please correct the code and the query..
Depends, if you're trying to delete one row then this is fine:
$sql="delete from cart where itemId='$itemId1'";
However to delete all it's simply:
$sql="DELETE * from cart";
The problem is not in the cart delete, it is in order.php. Two things I see here.
First up, you are opening each form inside the while loop but you don't close the form until outside the loop (and you never closed the <tr>s). This results in:
<form id="addform" method="post" action="cartdelete.php">
....
<form id="addform" method="post" action="cartdelete.php">
....
<form id="addform" method="post" action="cartdelete.php">
....
</form>
Only the outer form is closed. That corresponds to the first row on the table. No matter which submit button you click in the table, they all map back to the first one.
Second, I suggest you give each form a unique id.
echo "<form id=\"addform" . echo $row['itemId'] . "\" method="post" action="cartdelete.php"> ';
I have had instances of multiple forms on a page with the same id giving different results in different browsers.
$total = 0;
while ($row=mysqli_fetch_array($res))
{
$amount=$row['price']*$row['quantity'];
echo "<tr>";
echo "<td>" .$row['subtitle'] ."</td>";
echo "<td>" .$row['quantity'] ."</td>";
echo "<td>" .$row['price'] ."</td>";
echo "<td>" . $amount . "</td>";
echo "<form id='addform{$row['itemId']}' method='post' action='cartdelete.php'> ";
echo "<td><input type='submit' value='x' name='submit'></td>";
echo "<td><input type='text' name='itemId' value= '{$row['itemId']}'></td>";
echo"</form>";
echo "</tr>";
$total += $amount;
}
echo "</table>";
There is also a problem in the cartdelete.php. This line:
$sql1="select itemId from cart";
will only find the very first item in the cart. No matter what, it will never find the second or third item. It might not even be needed. Since I don't know the table structure, try this:
$itemId=(filter_input(\INPUT_POST,'itemId'));
if(!empty(\filter_input(INPUT_POST,'submit')))
{
$sql="delete from cart where itemId='$itemId'";
$res=mysqli_query($dbhandle,$sql) or die(\mysqli_error($dbhandle));
}
echo"deleted successfully";
$mysqli_close = \mysqli_close($dbhandle);

If functions per $row in a table

I have a table that shows me data from a call flow.
I need the Data from this table to be manipulated per row in such a way that all the values of my table, which are being looked up from my DB, (which are now in code) will be translated into a text value. Let me show U and explain:
My Table:
<?php
include_once "Connect2Martijn1.php";
?>
<link rel="stylesheet" href="CSSMartijn1.css">
</link>
<head>
<meta charset="iso-8859-1">
<meta name="description"content="VoizXL ">
<meta name="keywords"content="VoizXL ">
<meta name="author"content="Kenn Lo-A-Tjong">
</meta>
<title>Call Flow</title>
</head>
<fieldset>
<article class="rondehoeken">
<header>
<div class="streep1"></div>
<div class="streep2"></div>
<div class="streep3"></div>
<div class="streep4"></div>
<div class="streep5"></div>
<h1 id="artikel-titel" >Call Flow</h1>
</header>
<div id="artikel-container">
<table class="table 1">
<thead>
<title>Call Flow</title>
<meta charset = "UTF-8" />
<style type = "text/css">
table, td, th {
border: 1px solid black;
}
</style>
</thead>
<tbody>
<?php
$con=mysqli_connect("localhost","root","","voizxl_wachtrij");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Callflow");
echo "<table border='0'>
<tr>
<th>Nummer</th>
<th>Naam</th>
<th>Status</th>
<th>Time</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . $row['statusAnswered'] . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Example of (how I want to be) Translating the Data:
<?php
if ($row['statusAnswered'] ="NULL")
{
echo "Not Answered!";
}
else
{
echo "Answered!";
}
?>
What I want to Achieve is for eg. that the value in this table from $row['statusAnswered'] will be displayed in text as "Answered or Not Answered" if the Value of this row in the DB is NULL or Not...
How do I do this?
Right now I can only achieve to have 1 echo under the table saying Answered :S
No Idea how to put it per $row.
while($row = mysqli_fetch_array($result))
{
if (!isset($row['statusAnswered']))
{
$answered = "Not Answered!";
}
else
{
$answered = "Answered!";
}
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . $answered . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
if ($row['statusAnswered'] =="NULL"||$row['statusAnswered'] =="Null" || $row['statusAnswered'] =="null" || $row['statusAnswered'] =="")
{
echo "<td>Not Answered!</td>";
}
else
{
echo "<td>Answered!</td>";
}
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<table border='0'>
<tr>
<th>Nummer</th>
<th>Naam</th>
<th>Status</th>
<th>Time</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . ($row['statusAnswered']=='NULL'?'Not Answered!':'Answered!') . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
You could use;
$checkstatus = if($row['statusAnswered'] = NULL) { echo "Not Answered!"; } else {echo "Answered!";};
then call that by replacing;
echo "<td>" . $row['statusAnswered'] . "</td>";
with;
echo "<td>{$checkstatus}</td>"

Failed to pass an input variable to my query

I am creating a phonebook program, where I can register and create my own contact list. After login, the page will be directed to the tabmain page where I can view, add, edit or delete contact, in a multitab form.
Here's the problem: Whenever I click the save button (the button in function displayNew), it should be getting the first name and surname then, look for the database if there is a match. If not, then add it should them. Now, what happens is, after I click the save button, nothing is passed to the variable.
Here is my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Tab-View Sample</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="stylesheet" type="text/css" href="css_collect/distribution/tab-view.css" />
</head>
<body>
<?php $id = isset($_GET['id']) ? $_GET['id'] : 1; ?>
<?php
include 'conSql.php';
session_start();
$mySession = $_SESSION['user'];
//displays firsname and lastname of the user
$getNames = getNames($mySession);
$gET = explode("^", $getNames);
echo "Hi, "."<b>". $gET[0] ." ". $gET[1] ."</b>"."!";
echo "</br>";
echo "</br>";
?>
<div class="TabView" id="TabView">
<!-- ***** Tabs ************************************************************ -->
<div class="Tabs" style="width: 452px;">
<a <?=($id == 1) ? 'class="Current"' : 'href="sample.php?id=1"';?>>Contact List</a>
<a <?=($id == 2) ? 'class="Current"' : 'href="sample.php?id=2"';?>>Add contact</a>
<a <?=($id == 3) ? 'class="Current"' : 'href="sample.php?id=3"';?>>Edit / Delete</a>
</div>
<!-- ***** Pages *********************************************************** -->
<div class="Pages" style="width: 450px; height: 300px;">
<div class="Page" style="display: <?=($id == 1) ? 'block' : 'none';?>"><div class="Pad"></div>
list of query
</div>
<div class="Page" style="display: <?=($id == 2) ? 'block' : 'none';?>"><div class="Pad"></div>
<Form Name ='' Method ='GET' action = 'tabmenu.php'>
<?php
displayNew();
if(isset($_GET['btnAdd'])){
$fname = $_GET['txtFname'];
$lname = $_GET['txtLname'];
// $s = "SELECT * ";
// $s .="FROM tbl_contactlist ";
// $s .="WHERE fname = '". $_GET['txtFname'] ."' and lname = '". $_GET['txtLname'] ."'";
echo $s;
}
?>
</div>
<div class="Page" style="display: <?=($id == 3) ? 'block' : 'none';?>"><div class="Pad"></div>
<?php
displayEdit();
?>
</div>
</div>
</div>
<script type="text/javascript" src="css_collect/distribution/tab-view.js"></script>
<script type="text/javascript">
tabview_initialize('TabView');
</script>
<?php
function getNames($mySession){
//get the real name of the user (firstname and lastname)
$s = "SELECT * ";
$s .="FROM tbl_users ";
$s .="WHERE username = '". $mySession ."' ";
$rc = mysql_query($s);
$row = mysql_fetch_assoc($rc) or die();
$details = $row["fname"]."^".$row["lname"];
return $details;
}
function displayNew(){
echo "<table border = '0'>";
echo "<tr>";
echo "<td colspan='2'><b>New Contact</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2'>Please fill up the fields.</td>";
echo "</tr>";
echo "<tr>";
echo "<td>First Name: </td>";
echo "<td><input type='text' name='txtFname' id='txtFname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Last Name: </td>";
echo "<td><input type='text' name='txtLname' id='txtLname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Nick Name: </td>";
echo "<td><input type='text' name='txtNicname' id='txtNicname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Contact Number: </td>";
echo "<td><input type='text' name='txtContactNum' id='txtContactNum'></td>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td><input type='submit' name='btnAdd' id='btnAdd' value='SAVE'></td>";
echo "</tr>";
echo "</table>";
}
function displayEdit(){
echo "<table border = '0'>";
echo "<tr>";
echo "<td colspan='2'><b>Edit / Delete Page</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2'>You can edit or delete:</td>";
echo "</tr>";
echo "<tr>";
echo "<td>First Name: </td>";
echo "<td><input type='text' name='txtFname' id='txtFname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Last Name: </td>";
echo "<td><input type='text' name='txtLname' id='txtLname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Nick Name: </td>";
echo "<td><input type='text' name='txtNicname' id='txtNicname'></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Contact Number: </td>";
echo "<td><input type='text' name='txtContactNum' id='txtContactNum'></td>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td><input type='submit' name='btnEdit' id='btnEdit' value='EDIT'>";
echo "<input type='submit' name='btnDelete' id='btnDelete' value='DELETE'></td>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td><input type='submit' name='btnCancel' id='btnCancel' value='Cancel'></td>";
echo "</tr>";
echo "</table>";
}
function testMe(){
echo "<script type='text/javascript'>\n";
echo "alert('T E S T');\n";
echo "</script>";
}
?>
</body>
</html>
It looks like you don't ever close the form tag in the HTML, that might cause the page to not do anything when you click submit

Categories