2013-05-26 83 views
0

我在框架中有一个PHP变量,它需要同时传递给另外两个框架。其中一个框架每5秒刷新一次,并轻松从URL获取变量。其他框架不刷新,因为它是一种形式。该框架/表单需要在发送信息之前填充禁用的字段(可能在AJAX中可行,我不知道)。在帧之间传递php变量

我不熟悉HTML,CSS和基本PHP以外的任何东西,所以我已经挂了这个问题。

请参考代码和更多解释 - 谢谢!

嗯,我有一张照片,但由于我的名声太低,我无法向你展示......数字。

不管怎么说,这里是代码:

主框架页:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<title>Incident Entry</title> 
</head> 
<frameset border="0" frameborder="0" rows="50%,50%"> 
<frameset border="0" frameborder="0" cols="40%,60%"> 
<frame src="incidententry.php" name="topleft"> 
<frameset border="0" frameborder="0" rows="56%,44%"> 
<frame src="detailentry.php" name="toprighttop"> 
<frame src="details.php" name="toprightbottom"> 
</frameset> 
</frameset> 
<frame src="incidents.php" name="bottom"> 
</frameset> 
</html> 

incidents.php:

<?php header ('Refresh: 5'); 
session_start(); 
if($username); 
?> 
<!DOCTYPE html> 
<html lang="en"> 
<title>Incidents</title> 
<?php mysql_connect("-----", "-----", "------"); 
@mysql_select_db(-----_incidents); 
$sql2="SELECT * FROM incidents ORDER BY id DESC LIMIT 10"; 
$result2=mysql_query($sql2); 
$num=mysql_numrows($result2); 
?> 
<head> 
<link rel="stylesheet" type="text/css" href="output1.css"> 
<meta http-equiv="Page-Enter" content="blendTrans(Duration=0)"> 
<meta http-equiv="Page-Enter" content="revealtrans(duration=0.0"> 
<style type="text/css"> 
body{background-color:black} 
body{font-family:'trebuchet ms' } 
</style> 
</head> 
<body> 
<font color="white"> 
<div class="CSSTableGenerator"> 
<table border='0' rules='all' width='75%'> 
<tr class="hideextra"> 
<td>InC#</td> 
<td>Date</td> 
<td>Time</td> 
<td>City</td> 
<td>Dept</td> 
<td>Alarm Level</td> 
<td>Incident Type</td> 
<td>Address</td> 
<td width="53px">User</td> 
<td>Upgr</td> 
</tr> 
<?php 
$_GET['id']; 
while($row=mysql_fetch_array($result2)){ 
$id2 = $row['id']; 
$id = str_pad($id2,9, "2013-0000", STR_PAD_LEFT); 
$date=rtrim(ltrim($row['date'], "2013-"), "0..9,:"); 
$time=$row['time']; 
$city=$row['city']; 
$fire=$row['fire']; 
$addy=$row['addy']; 
$level=$row['level']; 
$desc=$row['desc']; 
$units=$row['units']; 
$who=$row['who']; 
echo "<tr>"; 
echo "<td style='white-space:nowrap;'><center>&nbsp<a href='http://www.------.com/pages/CAD/details.php?inci_num=$id' target='toprightbottom'>" . str_pad($row['id'],9,"2013-00000",STR_PAD_LEFT) . "</a></center></td>"; 
echo "<td style='white-space:nowrap;'><center>" . str_pad($date,6,'0',STR_PAD_LEFT) . "</center></td>"; 
echo "<td>" . $row['time'] . "</td>"; 
echo "<td>" . $row['city'] . "</td>"; 
echo "<td>" . $row['fire'] . "</td>"; 
echo "<td>" . $row['level'] . "</td>"; 
echo "<td>" . $row['desc'] . "</td>"; 
echo "<td>" . $row['addy'] . "</td>"; 
echo "<td>" . strtoupper($row['who']) . "</td>"; 
echo "<td><center><a href='http://www.------.com/pages/CAD/upgrade.php?id=$id2' target='_self'><img src='http://www.------.com/images/arrow_red_up.gif' height='16'></a></center></td>"; 
echo "</tr>"; 
echo "</div>"; 
} 
?> 
</table> 
</html> 

details.php:

<?php header ('Refresh: 5'); ?> 
<!DOCTYPE html> 
<html lang="en"> 
<title>Incident Details</title> 

<?php 
mysql_connect("-------", "-------", "------"); 
@mysql_select_db(------); 
$inci_num2=$_GET['inci_num']; 
$sql3="SELECT * FROM notes2 WHERE inci_num='$inci_num2' ORDER BY id DESC"; 
$result4=mysql_query($sql3); 
?> 
<head> 
<link rel="stylesheet" type="text/css" href="output1.css"> 
<style type="css/text"> 
body{background-color:black} 
body{font-family:'trebuchet ms' } 
</style> 
</head> 
<body bgcolor="black"> 
<font color="white"> 
<div class="CSSTableGenerator"> 
<table rules="all"> 
<tr class="hideextra"> 
<td>#</td> 
<td width="46px">Time</td> 
<td>Incident Notes</td> 
<td width="53px">User</td> 
</tr> 
<?php 
$_POST['inci_num']; 
while($row=mysql_fetch_array($result4)){ 
$id=$row['id']; 
$ipaddress=$row['ipaddress']; 
$inci_num=$row['inci_num']; 
$notes=$row['notes']; 
$Time1=$row['Time1']; 
$user=$row['who']; 
echo "<tr>"; 
echo "<td>&nbsp" . $row['inci_num'] . "</td>"; 
echo "<td>" . $row['Time1'] . "</td>"; 
echo "<td>" . $row['notes'] . "</td>"; 
echo "<td>" . $row['who'] . "</td>"; 
echo "</tr>"; 
echo "</div>"; 
} 
?> 
</table> 
</body> 

最后, detailentry.php:

<?php 
session_start(); 
if($username) 

ini_set('display_errors', 1); 
ini_set('log_errors', 1); 
ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); 
error_reporting(E_ALL); 
$id2=$_GET['inci_num2']; 
if(isset($_POST['submit'])){ 
$db=mysql_connect("------", "-----", "------") or die ("Cant connect"); 
$mydb=mysql_select_db("----_incidents") or die ("Cant find db"); 
$notes = mysql_real_escape_string($_POST['notes']); 
$who = strtoupper($_COOKIE['username']); 
$ipaddress = $_SERVER['REMOTE_ADDR']."\r\n"; 
$inci_num1 = $_POST['inci_num']; 
$inci_num = str_pad($inci_num1,9, "2013-0000", STR_PAD_LEFT); 
if(!isset($_POST["auto"])){ 
$sql = "INSERT INTO `notes2` (`id` , `inci_num` , `notes` , `who` , `ipaddress` , `Date` , `Time1`) VALUES (NULL, '".$inci_num."' , '".$notes."' , '".$who."' , '".$ipaddress."' , NOW(), DATE_ADD(NOW(),INTERVAL 120 MINUTE))"; 
}else{ 
$sql = "INSERT INTO `notes2` (`id` , `inci_num` , `notes` , `who` , `ipaddress` , `Date` , `Time1`) VALUES (NULL, '".$inci_num."' , '".$notes."' , '".$who."' , '".$ipaddress."' , NOW(), DATE_ADD(NOW(),INTERVAL 120 MINUTE))"; 
} 
$result = mysql_query($sql) or die ("Cant insert ".mysql_error()); 
if($result) 
{ 
} 
else 
{ 
}} 
?> 
<title>Detail Entry</title 
<head> 
<style type="css/text"> 
body{overflow-y:hidden; 
white-space-collapse:collapse;} 
body{background-color:black} 
body{font-family:'trebuchet ms' } 
.body{font-family:'trebuchet ms' } 
.hide{visibility:collapse; } 
#hide{visibility:collapse; } 
.nopad{padding-bottom:0px; margin-bottom:0px; } 
.borders{ } 
</style> 
</head> 
<body bgcolor="black" class="body" style="font-family:'trebuchet ms';"> 
<form action="detailentry.php" method="POST" style="white-space-collapse:collapse;"> 
<font color="white"> 
<table border="0" class="borders"> 
<tr> 
<td><font color="white" size="3">InC#:</font></td> 
<td><font color="white"><input type="text" maxlength="11" value="<?php echo $id2;?>" required name="inci_num">&nbsp RM911 ID:</font></td> 
<td><center><font color="white"><? echo strtoupper($_COOKIE['username']);?></font></center></td> 
</tr> 
<tr> 
<td><font color="white">Notes:</td> 
<td colspan="2"><textarea placeholder="Enter Incident Notes here" required rows="4" cols="36" name="notes"></textarea></td> 
</tr><input id="hide" style="visibility:collapse;" class="hide" hidden type="checkbox" name="auto" value="auto" checked> 
<tr class="nopad"> 
<td class="nopad" colspan="3" align="center"><input class="nopad" type="submit" name="submit" value="Submit"><input class="nopad" type="reset"></td> 
</tr> 
</table> 
</form> 
</body> 
</html> 

**注:我知道我应该使用新的语法,一次一件事。此外,我意识到代码更好,更易于阅读。再次,这是解决这个问题的第二位。

这就是我试图完成: 我需要从incidents.php页采取$id2变量并同时将其当用户点击号事件上incidents.php转移到既details.phpdetailentry.php。在detailentry.php,$id2需要在InC#:文本输入框中。

谢谢您的帮助!

+0

即时对不起,我真的没有得到你想要实现的,但是:但是: $ inci_num2 = $ _ GET ['inci_num']; $ sql3 =“SELECT * FROM notes2 WHERE inci_num ='$ inci_num2'ORDER BY id DESC”; 这部分是一个真正的问题请阅读: http://php.net/manual/en/security.database.sql-injection.php –

+0

是你需要的'$ username'变量吗? – slackmart

+0

我的歉意 - 我已经更新了我想要实现的内容 – Tim

回答

0

使用PHP会话;追加session_start();当你得到了$id2值使用开始每个文件的话,将其放到ID_2(会话变量):

$_SESSION['id_2'] = $id2; 

最后,当你需要ID_2值使用:

if (isset($_SESSION['id_2']) && $_SESSION['id_2'] != "") { 
    // do some things with the id_2 variable 
} 
+0

是有道理的,但detailingntry.php如何能够在不实际重新加载的情况下抓住'$ id2'?我担心,如果它重新加载,以前输入的数据将消失,人们会很不高兴。 – Tim