assigning result from a query to a variable within frames

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

armysierra
Forum Newbie
Posts: 5
Joined: Fri Jun 21, 2002 4:20 am

assigning result from a query to a variable within frames

Post by armysierra »

HELLO THERE,

i have a simple query in where i want to store the result to a variable that i could use in other pages or wthin the frameset.

ex:
MAIN.PHP3
$query = "SELECT TABLENAME FROM secretDB where USERNAME='$username' and PASSWORD='$password'";
$tblname1 = mysql_query($query);

$i=0;
while($row = mysql_fetch_array($tblname1)) {
$i=$i + 1;
$TABLENAME=$row["TABLENAME"];
$PRINCPAL=$row["PRINCIPAL"];
printf("%s", $row["TABLENAME"]);
}

(i dont want to print $PRINCIPAL here, what i want is store it in variable that i could pass to below (OPTION.PHP3)


OPTION.PHP3
$result = mysql_query("select DISTINCT COMPANY from dbase WHERE PRINCIPAL='THE VARIABLE IM TRYING TO BUILD");


PLEASE HELP ME!

ARMY
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Have a form on your page with hidden fields to hold the data, then the POST action of your form would be the page you want to call.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Frames seem to be causing a lot of problems for people here: Have you considered not using frames, they seem to be way more trouble than they're worth.

But if you really have to use frames look into using sessions to pass the information needed:
http://www.php.net/manual/en/ref.session.php
this will be especially useful if you want to be able to access the information in subsequent pages.

Mac
armysierra
Forum Newbie
Posts: 5
Joined: Fri Jun 21, 2002 4:20 am

Post by armysierra »

how do i do that?

i already have FORM but only the username & password will be enter, i dont want the client to put the PRINCIPAL on this form.

if this (<INPUT TYPE="hidden" NAME="$env_report" VALUE="xxxxxxx">
) will be added to my form, how will i write the correct code?

THANKS IN ADVANCE.

ARMY
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

<? PHP
print "<input type=\"hidden\" name=\"principal\" value=\"$PRINCIPAL\">";
?>
armysierra
Forum Newbie
Posts: 5
Joined: Fri Jun 21, 2002 4:20 am

Post by armysierra »

still dont work!

here's my complete code:
-----------------------------
MAIN.PHP3
<?

if($username && $password)
{
include("./Conn.php3");
//$loc="Location: http://$SERVER_NAME$SCRIPT_NAME";


$query = "SELECT TABLENAME, PRINCIPAL FROM secretDB where USERNAME='$username' and PASSWORD='$password'";
$tblname1 = mysql_query($query);
$tblname2 = mysql_query($query);


$num = mysql_num_rows($tblname1)
or die ("You're not authorized to be here. If you feel you have received this
message in error, please contact the <a
href=\"mailto:software@idess.com\">webmaster</a>");

$num = mysql_num_rows($tblname2)
or die ("You're not authorized to be here. If you feel you have received this
message in error, please contact the <a
href=\"mailto:software@idess.com\">webmaster</a>");


}

else
{

?>


<html>
<head>
<script language="javascript"><!--
function checkform ( form )
{
if (form.username.value == "") {
alert( "Please enter valid username.." );
form.username.focus();
return false ;
}
if (form.password.value == "") {
alert( "Please enter valid password.." );
form.password.focus();
return false ;
}

return true ;
}
//--></script>
<link rel="stylesheet" href="http://www.idess.com/ca/style1.css">
<title>IDESS Login Form</title>
</head>
<body>
<form method="post" action="<?php echo($SCRIPT_NAME)?>" onsubmit="return checkform(this);">
<input type="hidden" name="principal" value="$PRINCIPAL">
<br>
<center><img src="idesslogo.gif" width="50" height="50" border="0"></center>
<br>
<center><strong>You have entered IDESS Secured Directory</strong></center>
<br>
<table border=0 cellspacing=0 cellpadding=0 width=320 align=center>
<tr><td colspan=2><center><img src="lock.gif" width="22" height="27" border="0"></center></td></tr>
<tr><td colspan=2>&nbsp;</td></tr>
<tr><td>
Username:
</td><td>
<input name="username" type="text" width=10>
</td></tr>

<tr><td>
Password:
</td><td>
<input name="password" type="password" width=10>
</td></tr>
<tr><td colspan=2>&nbsp;</td></tr>
<tr><td colspan=2 align="center">
<input name="submit" type="submit" value="Authorize">
</td></tr>
</table>
</form>

<?


die(); //This will prevent PHP from showing actual page. See above.
}
?>



<html>
<head>
<title>Page</title>
</head>
<frameset rows="117,54, *" framespacing=0 border=0 frameborder=0>
<frameset cols="90,245,*">
<frame name="header" src="header.htm" scrolling="no" noresize>
<frame name="topmenu" src="/ccess/<?php $i=0; while($row = mysql_fetch_array($tblname1)) { $i=$i + 1; $TBLENAME=$row["TABLENAME"]; $principal=$row["PRINCIPAL"]; printf("%s", $row["TABLENAME"]);} ?>/menu.php3" scrolling="no" noresize target="input">
<frame name="input" src="/ccess/<?php $ii=0; while($row = mysql_fetch_array($tblname2)) { $ii=$ii + 1; $TBLENAME=$row["TABLENAME"]; $principal=$row["PRINCIPAL"]; printf("%s" , $row["TABLENAME"]);} ?>/option1.php3" scrolling="no" noresize target="result">
</frameset>
<frame name="print" src="print.htm" scrolling="no" noresize>
<frame name="result" src="empty.htm" scrolling="auto" noresize>
</frameset><noframes></noframes>


</html>

----------------------------------------------------

the $principal variable must go here:
(OPTION.PHP3)
<html>
<head>

<head>
<link rel="stylesheet" href="http://access/style1.css">
<title>Search Category Options</title>
<base target="result">
</head><body>
<br>
<br>
<br>
<br>
<br>

<!--//option dropdown start here-->
<?

include(".././Conn.php3");

<!--//WHEN CLICK THE FORM SUBMIT, THE VARIABLE MUST GO HERE, -->
$result = mysql_query("select DISTINCT COMPANY from dbase WHERE PRINCIPAL='$principal'");


$num_cols = mysql_num_rows($result);
$counter = 0;
echo "<FORM METHOD = \"POST\" ACTION=\"result1.php3\";\">\n";
echo "<table border=0 cellpadding=0 cellspacing=0 align=left width=350>\n";
echo "<tr><td>&nbsp;</td><td align=left>Search for:</td></tr>\n";
echo "<tr><td width=\"100\" align=right>Company:&nbsp;&nbsp;</td><td align=left>\n";

echo "<select name=\"company\">\n";
if ($company == "") {
echo "<option selected>&nbsp;</option>\n" ;
};
while($counter < $num_cols):
$opt = @mysql_result($result,$counter, "COMPANY");
echo "<option value='$opt'>$opt</option>\n" ;
$counter = $counter + 1;
endwhile;
echo "</select>\n";
echo "<INPUT TYPE=\"submit\" VALUE=\"Search\"></td></tr>\n";
echo "</table>\n";
echo "</FORM>\n";

?>
<!--//option dropdown ends here -->

</body>
</html>



WILL YOU PLEASE CHECK MY CODE?

ARMY
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

<form method="post" action="<?php echo($SCRIPT_NAME)?>" onsubmit="return checkform(this);">
<input type="hidden" name="principal" value="$PRINCIPAL">
Okay but you cannot just use a PHP variable in html, but you know this because you did it in the line above it "<?php echo($PRINCIPAL)?>"
armysierra
Forum Newbie
Posts: 5
Joined: Fri Jun 21, 2002 4:20 am

Post by armysierra »

STILL DONT WORK!

I'LL GET BACK IN 2DAYS.

THANKS A LOT FOLKS!


SINCERELY,
ARMY
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

I seem to feel like I need to construct another sticky. Why does it feel that way? :roll:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Maybe a sticky just filled with FAQs? But yes this topic is starting to crop up a lot.

Mac
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

I am actually considering a Read First forum, that way, it will cover anything.
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

Why do I think that still won't get people reading the forum before they post? Does that make me an old cynic? :(
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Yes it does :wink:

By the way where did you get your Monty Python image, it's cool.
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

Not entirely sure where mr gumby came from I went looking for him on some fan sites. I had to do some editing and resizing in photoshop to get him to look right though. I know it's copyright theft but I don't care, sorry jason (it's on your server). I suspect no one will ever know unless I tell everyone, DOH.
User avatar
e+
Forum Commoner
Posts: 44
Joined: Mon Jun 17, 2002 7:07 am
Location: Essex, UK

Post by e+ »

oh just relised I reached the ranks of scripter?
Post Reply