簡體   English   中英

在幀之間傳遞php變量

[英]passing php variables between frames

我在框架集的框架內有一個 PHP 變量,需要同時傳遞給其他兩個框架。 其中一個幀每 5 秒刷新一次,並且可以輕松地從 URL 中獲取變量。 另一個框架不會刷新,因為它是一個表單。 在發送信息之前,該框架/表單需要填充一個禁用字段(也許在 AJAX 中可行,我不知道)。

我不精通 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>

事件.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>

詳細信息.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>

**注意:我知道我應該使用新語法,請一次做一件事。 此外,我意識到代碼變得更好,更易於閱讀。 同樣,這對於解決這個問題來說是次要的。

這就是我要完成的:我需要花$id2從變量incidents.php頁面並同時將其轉移到兩個details.phpdetailentry.php當對這一事件數用戶點擊incidents.php detailentry.php$id2需要在Inc #:文本輸入框中。

提前謝謝你的幫助!!!

唔。 一個 8 歲的問題沒有人回答。 和 2 個“答案”只是不屑一顧的評論。

這是一個真正的答案:您可以通過創建會話變量在幀之間傳遞數據。 會話變量可在幀之間訪問。https://www.php.net/manual/en/reserved.variables.session.php有完整的信息。

我看到您在 3 個 php 文件中的兩個中有session_start() 將其添加到第三個的頂部。 然后用你想傳遞給另一個框架的任何值分配一個會話變量:

$_SESSION['vartopass']=$varyouwanttopass;

現在$_SESSION['vartopass']在以session_start()開頭的其他框架中可用。

$variwantedinthisframe=$_SESSION['vartopass'];

所以,是的,晚了8年。 你現在可能已經明白了這一點,但其他人還沒有,而且我討厭對任何人都沒有幫助的不屑一顧的言論。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM