You are here: help needed - passing values between two loads of the same page « PHP Programming Language « IT news, forums, messages
help needed - passing values between two loads of the same page

Posted by Joseph S. on 09/20/05 22:05

Hi,
How do I pass a string from one call to a php block to another call in
the
same page but from another form?

Here's my full php code:

I'm using two forms in the same page. A hidden field 'f' with values
'1' and
'2' are used to distinguish calls from one form from those from the
other.

<html>
<head><title>Database Access</title></head>
<body>

<form name="QueryForm" action="db2.php" method="POST" />

<input type="hidden" name="f" value="1" />

<input type="text" width="100" name="txtQuery"
value="select * from license_master;" /> <br/>

<input type="submit" name="Query" value="Query" /> <br/>
</form>

<?php
$s = ""; $nl = "<br/>";
switch ($_POST['f']){
case '1':
$conn=odbc_connect('mysqldsnone','root','katipatang');
$sql = $_POST['txtQuery'];
$rs=odbc_exec($conn,$sql);
echo "<table width=\"60%\">\n";
while (odbc_fetch_row($rs)){
$abbr=odbc_result($rs,"abbr");
$fullname=odbc_result($rs,"fullname");
$link=odbc_result($rs,"link");
echo "<tr>
<td colspan=\"3\" background=\"blue.png\">
<p class=\"white-text\">".$abbr."</p></td></tr>\n";

echo "<tr><td>".$abbr."</td><td>".$fullname
."</td><td><a
href=\"".$link."\">".$link."</a></td></tr>\n";

$s .= $abbr.",".$fullname.",".$link."\n";
//making the comma separated string here
}

//*************************************************************************
/*
PROBLEM: somehow pass $s, which now contains the data in csv form
to the next call of the same page from the second form which is below
tried cookies but they do not work because you can only set a cookie
right
at the start of the page
*/
//*************************************************************************

echo "</table>\n";
odbc_close($conn);
break;
case '2':
$of = $_POST['outputfile'];
$of ="C:/Program Files/Apache Group/Apache2/htdocs/php/lm.csv";
$handle = fopen($of,"w+");
if (!$handle){echo "Cannot open file $of for writing".$nl;}
if (!fwrite($handle,$s)){echo "Cannot write to file $of".$nl;}
fclose($handle);
break;
default:
;
}
?>
<form name="ExportForm" action="db2.php" method="POST" />

<input type="hidden" name="f" value="2" /><br/>

<input type="text" name="outputfile" value="lm.csv" /> <br/>
<input type="submit" name="SubmitExport" value="Export" />
<br/>
</form>
</body>
</html>

How do I get the value I stored into $s in case '1', when execution
moves to case '2'?

Any help is greatly appreciated.
Thanks in advance.
Joseph S.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация