In a form there is a text field and a table. If we put a value in that text field the corresponding name needs to be displayed on the table:
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<center><table>
<tr><td>no</td><td><input type="text" name="no" autofocus></td></tr>
</table></center>
<br>
<br>
<center>
<table cellpadding="0" cellspacing="0" width="60%" border='1' bgcolor="#999999">
<thead>
<tr>
<th> Element_Number</th>
</tr>
</thead>
<?php
if(isset($_POST['no']))
{
$c=mysql_connect("localhost","root","");
mysql_select_db("test");
if(!$c)
{
echo "db prob".mysql_error();
}
$no=$_POST['no'];
$qry=mysql_query("select name from opt where no='$no'");
if(!$qry)
{
echo "ret".mysql_error();
}
if(mysql_num_rows($qry)!=0)
{
$row=mysql_fetch_array($qry);
$name=$row['name'];
}
else
{
echo "query Invalid";
}
echo "<td>" .$name."</td></tr>" ;
}
?>
Using this code the value enters in the table but I want to add the name frequently the value to the table as next row when the next value enter to the text field
do it with the help of ajax
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<center>
<table>
<tr><td>no</td><td><input type="text" name="no" autofocus></td></tr>
<tr><input type="button" name="submit" value="submit"></tr>
</table></center>
</form>
<br>
<br>
<center>
<table id="test_table" cellpadding="0" cellspacing="0" width="60%" border='1' bgcolor="#999999">
<thead>
<tr>
<th> Element_Number</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
$(document).ready(function(){
$('#submit').click(function(){
var no=$('[name="no"]');
$.post('your_current_page_name.php',{"no":no},function(data){
$("#test_table> tbody").append(data);
});
});
});
</script>
<?php
if(isset($_POST['no']))
{
$c=mysql_connect("localhost","root","");
mysql_select_db("test");
if(!$c)
{
echo "db prob".mysql_error();
}
$no=$_POST['no'];
$qry=mysql_query("select name from opt where no='$no'");
if(!$qry)
{
echo "ret".mysql_error();
}
if(mysql_num_rows($qry)!=0)
{
$row=mysql_fetch_array($qry);
$name=$row['name'];
}
else
{
echo "query Invalid";
}
echo "<tr><td>" .$name."</td></tr>" ;
}
Related
i been trying to solve this problem for a few hours but still no progress. Want to Echo out my database result onto a table created in my html however it just pop out on the side of the window. Please advice something i can do. Thank you.
PHP
if (isset($_POST['search'])) {
include 'dbh.php';
$uid =$_POST['name1'];
$nric = $_POST['nric1'];
$number = $_POST['number1'];
$sql = "SELECT * FROM user WHERE name = '$uid' OR nric = '$nric' OR contact = '$number' ";
$result = $conn->query($sql);
if (!$row = mysqli_fetch_assoc($result))
{
echo "No result is found! ";
}
else
{
echo "result found";
$_SESSION['id'] = $row['id'];
echo "<tr>";
echo "<td>".$row['no']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['surname']."</td>";
echo "<td>".$row['nric']."</td>";
echo "<td>".$row['contact']."</td>";
echo "<td>".$row['gender']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['address']."</td>";
echo "<td>".$row['date']."</td>";
echo "</tr>";
}
}
Inside my form method.
<!-- Search function aboutus about us website -->
<form method="post" action="" >
<div class="panel" id="aboutus">
<h1>About Us</h1>
<!-- end of header -->
<input type="text" name="nric1"
placeholder="NRIC"><br> <input type="text" name="name1"
placeholder="Name"><br>
<input type="text" name="number1" placeholder="Details Number"><br>
<table width = "300" border = "1" cellpadding="1" cellspacing="1">
<tr>
<th>No</th>
<th>Name</th>
<th>Surname</th>
<th>Nric</th>
<th>Contact</th>
<th>Gender</th>
<th>Email</th>
<th>Address</th>
<th>Data</th>
<tr>
</table>
<input type="submit" name="search" value="Search">
</form>
Of course it does that,you need to echo it in the proper place,inside the HTML.Assuming the you also have the HTML inisde the same php page
<form method="post" action="" >
<div class="panel" id="aboutus">
<h1>About Us</h1>
<!-- end of header -->
<input type="text" name="nric1"
placeholder="NRIC"><br> <input type="text" name="name1"
placeholder="Name"><br>
<input type="text" name="number1" placeholder="Details Number"><br>
<table width = "300" border = "1" cellpadding="1" cellspacing="1">
<tr>
<th>No</th>
<th>Name</th>
<th>Surname</th>
<th>Nric</th>
<th>Contact</th>
<th>Gender</th>
<th>Email</th>
<th>Address</th>
<th>Data</th>
<tr>
<?php ...else{
$_SESSION['id'] = $row['id'];
echo "<tr>";
echo "<td>".$row['no']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['surname']."</td>";
echo "<td>".$row['nric']."</td>";
echo "<td>".$row['contact']."</td>";
echo "<td>".$row['gender']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['address']."</td>";
echo "<td>".$row['date']."</td>";
echo "</tr>";
?>
</table>
<input type="submit" name="search" value="Search">
</form>
i'm creating asset database system (just an offline system, not connected to internet) that will show all assets list. on the list, i can click on any asset to view the details. also i'm manage to update the details or delete the asset. but when it goes to asset record parts, it give an error on inserting record to asset using a form.
here is my record add form. and i'm also wanna make machine id visible under MACHINE ID field in the form, but i did't know yet how to put the data there.
for inserting record, its will capture machine id on rekod_add.php ( record add) url address from asset table to passing into rekod_tab table.
here is my record add page ( rekod_add.php )
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body,td,th {
font-family: Tahoma, Geneva, sans-serif;
}
</style>
</head>
<body>
<script type="text/javascript">function checkinput() {
var id_mesin = document.getElementById('id_mesin').value;
if(!id_mesin.match(/\S/)) {
alert ('Please enter Machine ID');
return false;
} else {
return true;
}
}
</script>
<?php
$con=mysqli_connect("localhost","root","admin","exa");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id_mesin = $_POST['id_mesin'];
$query = "SELECT * FROM asset WHERE id_mesin ='".$id_mesin."'";
$result = mysqli_query($con,$query);
$rows = mysqli_fetch_array($result);
?>
<table width="733" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form_insert" method="post" action="rekod_add_ac.php">
<table width="709" border="0" align="center">
<tr>
<th width="23" scope="col">MACHINE ID</th>
<th colspan="2" scope="col">DATE</th>
<th width="68" scope="col">TIME</th>
<th width="175" scope="col">RECEIVE CALL BY</th>
<th width="97" scope="col">CURRENT METER</th>
<th width="90" scope="col">LAST METER</th>
<th width="136" scope="col">J.SHEET NO</th>
</tr>
<tr>
<td> </td>
<td colspan="2"><input name="tarikh_rekod" type="text" id="tarikh_rekod" size="15" /></td>
<td><input name="time" type="text" id="time" size="10" maxlength="9" /></td>
<td><input type="text" name="call_by" id="call_by" /></td>
<td><input name="meter_semasa" type="text" id="meter_semasa" size="15" /></td>
<td><input name="meter_last" type="text" id="meter_last" size="15" /></td>
<td><input name="rujukan" type="text" id="rujukan" size="10" /></td>
</tr>
<tr>
<td> </td>
<th width="81">PROBLEM</th>
<th width="5">:</th>
<td colspan="3"><textarea name="masalah" id="masalah" cols="55" rows="5"></textarea></td>
<th colspan="2" rowspan="2"><p>REMARK</p>
<p>
<textarea name="remark" cols="30" rows="6" id="remark"></textarea>
</p></th>
</tr>
<tr>
<td> </td>
<th>SOLUTION</th>
<th>:</th>
<td colspan="3"><textarea name="solution" id="solution" cols="55" rows="5"></textarea></td>
</tr>
<tr>
<td colspan="8" align="right"><?php echo "<input type='hidden' value='" . $rows['id_mesin'] . "' name='id_mesin'>"; echo "<input type='submit' value='Add Record'>";?></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<?php
mysqli_close($con);
?>
</body>
</html>
here is my rekod_add_ac.php
<?php
session_start();
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<script type="text/javascript">
<!--
function CloseWindow() {
window.close();
window.opener.location.reload();
}
//-->
</script>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
$con=mysqli_connect("localhost","root","admin","exa");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
print_r($_POST);
$id_mesin=$_POST['id_mesin'];
$tarikh_rekod=$_POST['tarikh_rekod'];
$time=$_POST['time'];
$call_by=$_POST['call_by'];
$meter_semasa=$_POST['meter_semasa'];
$meter_last=$_POST['meter_last'];
$rujukan=$_POST['rujukan'];
$masalah=$_POST['masalah'];
$solution=$_POST['solution'];
$remark=$_POST['remark'];
$rekod_in="INSERT INTO rekod_tab ( id_mesin, tarikh_rekod, time, call_by, meter_semasa, meter_last, rujukan, masalah, solution, remark) VALUES ( $'id_mesin', $'tarikh_rekod', $'time', $'call_by', $'meter_semasa', $'meter_last', $'rujukan', $'masalah', $'solution', $'remark')";
$result=mysqli_query($con, $rekod_in);
if($result){
echo "Successful";
echo "<BR>";
echo "<th><form>";
echo "<input type='button' onClick='CloseWindow()' value='Back to Exa_mySQL' align='middle'>";
echo "</form></th>";
}
else {
echo "Data error, please recheck before submit.";
echo "<BR>";
echo "Click back to add record.";
echo "<BR>";
echo "<form action='rekod_add.php?id=$id_mesin' method='post'>";
echo "<td><input type='hidden' value='$id_mesin' name='id_mesin'>";
echo "<input type='submit' value='Back'></td>";
echo "</form>";
echo "<th><form>";
}
mysqli_close($con);
?>
</body>
</html>
after user done inserting record details, the form will add the record on rekod_tab table including machine id ( id_mesin ) which automatically capture from url like i said before.
but the result is error. when inserting detail manual in sql, its work. can anyone help me?
here my error result.
sorry for my bad english.
Try INSERT query like this
$rekod_in="INSERT INTO rekod_tab
( id_mesin, tarikh_rekod, time, call_by, meter_semasa, meter_last,
rujukan, masalah, solution, remark)
VALUES ( '$id_mesin', '$tarikh_rekod', '$time', '$call_by', '$meter_semasa',
'$meter_last', '$rujukan', '$masalah', '$solution', '$remark')";
I have this PHP code/form:
<form method="post" action="tickets_report2.php">
<table width="800" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><strong>Select</strong></td>
<td><strong>Company</strong></td>
</tr>
<?php
$sql="SELECT * from customer ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
$counter=0;
while($result=mysql_fetch_array($rs)) {
$counter++;
echo '<tr>
<td><input type="checkbox" value="'.$result["sequence"].'" name="checkbox'.$counter.'" /></td>
<td>'.$result["company"].'</td>
</tr>';
}
echo '<input type="hidden" name="counter" value="'.$counter.'" />';
?>
</table>
<input type="submit" name="submit" value="Next" />
</form>
and on the form action page:
<table width="800" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><strong>Company</strong></td>
</tr>
<?php
for($i=1; $i<=$_POST["counter"]; $i++) {
if($_POST["checkbox$i"]) {
$sql="SELECT * from customer where sequence = '".$i."' ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
$result=mysql_fetch_array($rs);
echo '<tr>
<td>'.$result["company"].'</td>
</tr>';
}
}
?>
</table>
lets say i check the checkbox on the form for the row in the database with sequence of 278, the SQL Query should say SELECT * from customer where sequence = '278' but its showing SELECT * from customer where sequence = '1'
i think its using the counter rather than the customer sequence
what do i need to change to get this working correctly so it selected the correct customer(s)
On the form action page it should read:
if($_POST["checkbox$i"]) {
$sql="SELECT * from customer where sequence = '".$_POST["checkbox$i"]."' ";
Note: sanitize your inputs.
form page:
<form method="post" action="tickets_report2.php">
<table width="800" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><strong>Select</strong></td>
<td><strong>Company</strong></td>
</tr>
<?php
$sql="SELECT * from customer ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
$counter=0;
while($result=mysql_fetch_array($rs))
{
$counter++;
echo '<tr>
<td><input type="checkbox" value="'.$result["sequence"].'" name="checkbox['.$counter.']" /></td>
<td>'.$result["company"].'</td>
</tr>';
}
?>
</table>
<input type="submit" name="submit" value="Next" />
</form>
action page:
<table width="800" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><strong>Company</strong></td>
</tr>
<?php
foreach($_POST["checkbox"] as $value)
{
$sql="SELECT * from customer where sequence = '".$value."' ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
$result=mysql_fetch_array($rs);
echo '<tr>
<td>'.$result["company"].'</td>
</tr>';
}
?>
</table>
I am currently using this javscript and PHP code
<script>
function add(total)
{
form2.thetotal.value = document.forms["form1" + total].total.value;
}
</script>
<form name="form2">
<table width="800" border="0" cellspacing="0" cellpadding="10" style="position:fixed; z-index:-999; background-color:#FFF;">
<tr bgcolor="#eeeeee">
<td> </td>
<td colspan="2" width="50%"><strong>Total: </strong><input type="text" name="thetotal" id="thetotal" size="20" value="0" /></td>
<td colspan="2" width="50%"><strong>VAT:</strong> </td>
</tr>
<tr bgcolor="#eeeeee">
<td width="5%"> </td>
<td width="20%"><strong>Invoice Number</strong></td>
<td width="35%"><strong>Company</strong></td>
<td width="20%"><strong>Date</strong></td>
<td width="20%"><strong>Total</strong></td>
</tr>
</table>
</form>
<form name="form1">
<table width="800" border="0" cellspacing="0" cellpadding="10">
<?php
$sql="SELECT * from billing_pdf_archive order by invoice_number ASC ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
while($result=mysql_fetch_array($rs))
{
$counter++;
$sql2="SELECT * from customer where sequence = '".$result["customer_sequence"]."' ";
$rs2=mysql_query($sql2,$conn) or die(mysql_error());
$result2=mysql_fetch_array($rs2);
$sql3="SELECT * from reseller where sequence = '".$result["reseller_sequence"]."' ";
$rs3=mysql_query($sql3,$conn) or die(mysql_error());
$result3=mysql_fetch_array($rs3);
if($result["customer_sequence"] != '0')
{
$company = $result2["company"];
}
elseif($result["reseller_sequence"] != '0')
{
$company = '<strong>Reseller: </strong>'.$result3["company"];
}
$total = $result["total"];
echo '<tr>
<td width="5%"><input type="checkbox" name="check" id="check" onclick=\'add('.$total.');\' /></td>
<td width="20%">'.$result["invoice_number"].'</td>
<td width="35%">'.$company.'</td>
<td width="20%">'.$result["datetime"].'</td>
<td width="20%">£'.$result["total"].'</td>
</tr>';
}
?>
</table>
</form>
so as you can see it is selecting from the MySQL database and i am trying to make it so when one of the checkboxes is ticked it adds the total into the "thetotal" text field (in form 2) but it is just leaving that box as zero - any ideas on what i could do?
You did not specify the total field for form 1, then it raised javascript error, it wont work.
Check it out
<script>
function add(total)
{
form2.thetotal.value = total + parseFloat(document.form1.formtotal.value);
}
</script>
<form name="form1">
<!-- replace field name formtotal with anything that you want-->
<!-- replace field value with anything that you get from your mysql result-->
<input type="text" name="formtotal" id="formtotal" value="10" />
</form>
Here is how you can do it (assuming total is int and not float):
<script>
function add(total, this_chk_bx)
{
//(if its float, use `parseFloat` instead of `parseInt`)
if(this_chk_bx.checked==true){
//add if its checked
var tot_1 = parseInt(form2.thetotal.value);
form2.thetotal.value = tot_1+parseInt(total);
}
else{
//subtract if its unchecked
}
}
</script>
.
in your php, you have to send the checkbox like this:
onclick=\'add('.$total.', this);\'
.
This is my code:
<?php
function GetDays($sStartDate, $sEndDate){
$sStartDate = gmdate("Y-m-d", strtotime($sStartDate));
$sEndDate = gmdate("Y-m-d", strtotime($sEndDate));
$aDays[] = $sStartDate;
$sCurrentDate = $sStartDate;
while($sCurrentDate < $sEndDate){
$sCurrentDate = gmdate("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate)));
$aDays[] = $sCurrentDate;
}
return $aDays;
}
?>
<html>
<head>
<script language="JavaScript" src="calendar_us.js"></script>
<link rel="stylesheet" href="calendar.css">
</head>
<body background="mainbg.JPG">
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<?
//If we submitted the form
if(isset($_POST['submitMe']))
{
$sec=00;
$sc=00;
$name=$_POST['name'];
$mm=substr($_POST['testinput'],0,2);
$dd=substr($_POST['testinput'],3,2);
$yy=substr($_POST['testinput'],6,4);
$sdate = $yy."-".$mm."-".$dd;
$mn=substr($_POST['test'],0,2);
$dn=substr($_POST['test'],3,2);
$yn=substr($_POST['test'],6,4);
$edate = $yn."-".$mn."-".$dn;
$host="10.207.100.10";// Host name
$username="root";// Mysql username
$password="######"; // Mysql password
$db_name="wtems"; // Database name
$tbl_name="constellation_reserve"; // Table name // Connect to server and selectdatabse
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM constellation_reserve where CID=$name and (start_date between '$sdate' and '$edate' or end_date between '$sdate' and '$edate')";
$result=mysql_query($sql); // Define$color=1
if($result)
{
$color="1";
echo '<table border="0" cellpadding="8" align="center">';
echo'<tr>';
echo'</tr>';
echo'<tr>';
echo'</tr>';
echo '<tr><h3 align="center"<font color="white">RESERVATION </font></h3></tr>';
echo'<tr>';
echo'</tr>';
echo'<tr>';
echo '<table width="500" height="300" border="0" align="center" cellpadding="8" cellspacing="2">';
$fields_num = mysql_num_fields($result);
echo "<tr bgcolor='#0099FF'>";
echo "<td><FONT COLOR='FFFFFF'>ID</FONT> </td>";
echo "<td><FONT COLOR='FFFFFF'>START DATE</FONT></td>";
echo "<td> <FONT COLOR='FFFFFF'>RESERVED BY </FONT></td>";
echo "<td><FONT COLOR='FFFFFF'>END DATE</FONT></td>";
echo "</tr>\n";
while($rows=mysql_fetch_array($result))
{ // If $color==1 table row color = #FFC600
if($color==1)
{
echo "<tr bgcolor='#FFFFDD'>
<td>".$rows['CID']."</td><td>".$rows['start_date']."</td><td bgcolor='#99AAFF'><FONT COLOR='FFFFFF'>".$rows['owner']."</FONT></td><td>".$rows['end_date']."</td></tr>";
// Set$color==2, for switching to other color
$color="2";
} // When$color not equal 1, use this table row color
else
{
echo "<tr bgcolor='#FFFFEE'><td>".$rows['CID']."</td><td>".$rows['start_date']."</td><td bgcolor='#99AAFF'><FONT COLOR='FFFFFF'>".$rows['owner']."</FONT></td><td>".$rows['end_date']."</td></tr>";// Set $color back to 1
$color="1";
}
}
echo '</table>';
mysql_close();
echo '</tr>';
echo '</table>';
}
else
{
echo '<table border="0" cellpadding="8" align="center">';
echo '<tr><h3 align="center"<font color="white">NoDataFound</font></h3></tr>';
echo '</table>';
}
}
//If we haven't submitted the form
else
{
?>
<h3 align="center"<font color="white">REPORT DETAILS</font></h3>
<table border="1" cellpadding="8" align="center">
<br>
</br>
<tr><td align="left">Constellation ID</td><td>:</td><td> <input type="text" name="name" /></td></tr>
<tr><td align="left">Start Date</td><td>:</td><td> <input type="text" name="testinput" />
<script language="JavaScript">
new tcal ({
// form name
//'formname': 'testform'
// input name
'controlname': 'testinput'
});
</script>
</td></tr>
<tr><td align="left">End Date</td><td>:</td><td> <input type="text" name="test" />
<script language="JavaScript">
new tcal ({
// form name
//'formname': 'testform'
// input name
'controlname': 'test'
});
</script>
</td></tr>
</table>
<br>
</br>
<br>
</br>
<p align="center"><input type="submit" value="REPORT" name="submitMe"></p>
<?php
}
?>
</form>
</body>
</html>
when i execute the code is working fine but, the datas are not displaying in the same page.
when the data are displaying the page is refreshing so i cant view the data in same page.
You should never use a root username and password when you are developing an app, create an account and use, when you post remove it.
The issue has to be coming from your JavaScript if your page refreshes after loading. PHP is a server side language, meaning it can redirect before user output but not after. Post your JS or a link to the page here so we can help more.
Seconding #ProNeticas -- NEVER ever use your root password when you are developing an app.
Also your code is open to SQL injection -- please read about mysql_real_escape_string
#user.. i just format your code... please look and apply... then we'll discuss on your problem...
<?php
function GetDays($sStartDate, $sEndDate){
$sStartDate = gmdate("Y-m-d", strtotime($sStartDate));
$sEndDate = gmdate("Y-m-d", strtotime($sEndDate));
$aDays[] = $sStartDate;
$sCurrentDate = $sStartDate;
while($sCurrentDate < $sEndDate){
$sCurrentDate = gmdate("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate)));
$aDays[] = $sCurrentDate;
}
return $aDays;
}
?>
<html>
<head>
<script type="javascript" src="calendar_us.js"></script>
<link rel="stylesheet" href="calendar.css" >
</head>
<body background="mainbg.JPG">
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<?
//If we submitted the form
if(isset($_POST['submitMe']))
{
$sec=00;
$sc=00;
$name=$_POST['name'];
$mm=substr($_POST['testinput'],0,2);
$dd=substr($_POST['testinput'],3,2);
$yy=substr($_POST['testinput'],6,4);
$sdate = $yy."-".$mm."-".$dd;
$mn=substr($_POST['test'],0,2);
$dn=substr($_POST['test'],3,2);
$yn=substr($_POST['test'],6,4);
$edate = $yn."-".$mn."-".$dn;
$host="#######";// Host name
$username="#####";// Mysql username
$password="######"; // Mysql password
$db_name="####"; // Database name
$tbl_name="constellation_reserve"; // Table name // Connect to server and selectdatabse
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM constellation_reserve where CID=$name and (start_date between '$sdate' and '$edate' or end_date between '$sdate' and '$edate')";
$result=mysql_query($sql); // Define$color=1
$fields_num = mysql_num_fields($result);
if($result)
{ ?>
<table border="0" cellpadding="8" cellspacing="5" align="center">
<tr>
<td><h3 align="center"<font color="white">RESERVATION </font></h3></td>
</tr>
<tr>
<td>
<table width="500" height="300" border="0" align="center" cellpadding="8" cellspacing="2">
<tr style="color:#fff;background-color:#0099FF">
<td>ID</td>
<td>START DATE</td>
<td>RESERVED BY</td>
<td>END DATE</td>
</tr>
<?php
while($rows=mysql_fetch_array($result))
{ $color=1;
// If $color==1 table row color = #FFC600
if($color == 1){ ?>
<tr background-color='#FFFFDD'>
<td><?php echo $rows['CID']?></td>
<td><?php echo $rows['start_date'];?></td>
<td style="color:#FFF;background-color:#99AAFF'><?php echo $rows['owner'];?></td>
<td><?php echo $rows['end_date']?></td>
</tr>
<?php $color=2;
} else { ?>
<tr background-color='#FFFFEE'>
<td><?php echo $rows['CID'];?></td>
<td><?php echo $rows['start_date'];?></td>
<td style="color:#FFF;background-color:#99AAFF'><?php echo $rows['owner'];</td>
<td><?php echo $rows['end_date'];?></td>
</tr>
<?php $color=1;
}
} ?>
</table>
<?php mysql_close(); ?>
</td>
</tr>
</table>
<?php } else { ?>
<table border="0" cellpadding="8" align="center">
<tr><h3 align="center"style="color:#fff">NoDataFound</h3></tr>
</table>
<?php }
} //If we haven't submitted the form
else { ?>
<h3 align="center"<font color="white">REPORT DETAILS</font></h3>
<table border="1" cellpadding="8" align="center">
<tr>
<td align="left">Constellation ID</td>
<td>:</td>
<td> <input type="text" name="name" /></td>
</tr>
<tr>
<td align="left">Start Date</td>
<td>:</td>
<td> <input type="text" name="testinput" />
<script type="javascript">
new tcal ({
// form name
//'formname': 'testform'
// input name
'controlname': 'testinput'
});
</script>
</td>
</tr>
<tr>
<td align="left">End Date</td>
<td>:</td>
<td> <input type="text" name="test" />
<script typr"javascript">
new tcal ({
// form name
//'formname': 'testform'
// input name
'controlname': 'test'
});
</script>
</td>
</tr>
</table>
<p align="center"><input type="submit" value="REPORT" name="submitMe"></p>
<?php } ?>
</form>
</body>
</html>