这是我的代码:
<?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>
当我执行代码工作正常但是,数据不显示在同一页面中。 当数据显示时,页面正在刷新,因此我无法在同一页面中查看数据。
答案 0 :(得分:1)
在开发应用,创建帐户并使用时,不应使用root用户名和密码,当您发布删除它时。
如果您的网页在加载后刷新,则问题必须来自您的JavaScript。 PHP是服务器端语言,这意味着它可以在用户输出之前重定向,但不能在之后重定向。将您的JS或链接发布到此处,以便我们提供更多帮助。
答案 1 :(得分:0)
借调@ProNeticas - 从不在开发应用时使用root密码。
此外,您的代码向SQL injection开放 - 请阅读mysql_real_escape_string
答案 2 :(得分:0)
@user ..我只是格式化您的代码......请查看并申请...然后我们将讨论您的问题......
<?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>