Page 1 of 1
session variable gets value when clocked on url
Posted: Tue May 18, 2004 10:46 am
by Zooter
Hi,
I have a page that returns a resultset of a query I made to mySQL db. There is a certain field in the results that has to be clickable so I can then go to a page with more detail of that certain record. I know I can put the value I want to send to the next page in the URL and then just use it, but I don't want to send info in the URL.
How do I assign a session variable with a value depending on which record's field URL I click? I've spent almost 6 hours on the net already trying to find a solution...
I'm using PHP 4.3.6 on IIS 5 with WinXP.
Any help will be appreciated
Posted: Tue May 18, 2004 10:51 am
by dave420
Make a form that posts back to the script. On each record, make a javascript link that sets a value in a hidden field in the form, and submits the form. That will give you click->posting, which is what you need. The script can then check if anything's posted to it, and act accordingly if it has.
Posted: Tue May 18, 2004 10:54 am
by Zooter
Thanks I will try that. Let you know what happens.
Cheers
Posted: Tue May 18, 2004 11:05 am
by Zooter
I'm usgin PHP in Dreamweaver MX... How do I post the form back to the script in Dreamweaver?
Here's the code with the repeat region on the records where the hyperlink also is...
<?php while ($row = mysql_fetch_assoc($ClientSearch)) { ?>
<tr bgcolor="#C1D8E6">
<td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><a href="AdminClientInfoPolicy.php?IDNumber=<?php echo $row["IDNumber"]; ?>"><?php echo $row["Surname"]; ?></a></font></div></td>
<td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo $row["Initials"]; ?></font></div></td>
<td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo $row["PostalAddrTown"]; ?></font></div></td>
<td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo $row["PhoneHome"]; ?></font></div></td>
<td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo $row["PhoneBus"]; ?></font></div></td>
<td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo $row["PhoneCell"]; ?></font></div></td>
<td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><?php echo $row["Broker"]; ?></font></div></td>
</tr>
<tr>
<td> </td>
<td><font size="2" face="Arial, Helvetica, sans-serif"> </font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif"> </font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif"> </font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif"> </font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif"> </font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif"> </font></td>
</tr>
<?php } ?>
Posted: Tue May 18, 2004 11:15 am
by JayBird
Please read this before making any more posts
viewtopic.php?t=21171
Thanks
Mark
Posted: Tue May 18, 2004 11:16 am
by dave420
Change the href to:
Code: Select all
javascript:adminClientInfoPolicy("<?=$rowї"IDNumber"];?>");
then add a function to the page that will do the form-based stuff:
Code: Select all
<script language="javascript>
function adminClientInfoPolicy(id) {
document.formname.IDNumber.value=id;
document.formname.submit();
}
</script>
Then, finally, put a form in the document:
Code: Select all
<form name="formname" method="post">
<input type=hidden name="IDNumber">
</form>
And that'll do it

You might want to ensure the javascript works on every platform you want it to...
Posted: Tue May 18, 2004 11:37 am
by Zooter
Thanks for the help
Posted: Wed May 19, 2004 10:35 am
by Zooter
Thanks alot. It worked...
Posted: Tue May 25, 2004 5:49 pm
by Zooter
This hyperlink works now. Another problem is now one of leading zero's being thrown away by the function...
The value of
in
Code: Select all
javascript:adminClientInfoPolicy("<?=$rowї"IDNumber"];?>");
sometimes is something like 0020956799. But when it assign this value to the hidden field and it gets submitted, the value changes to 20956799. All the leading zero's are discarded, and suddelny the results on the next page can't display correctly, because the IDNumber isn't identical to the one that is actually needed there. And also I'm assigning this value to a $_POST['IDNumber'] variable in the next page. Don't know if this has something to do with it.
Is there a way to assign this value to the hidden field so that the identical string gets sent and assigned to the $_POST variable in the next page?
Regards
Posted: Tue May 25, 2004 6:17 pm
by feyd
is it always 10 digits?
<?= sprintf("%010d",$row['IDNumber']); ?>
Posted: Tue May 25, 2004 6:44 pm
by Zooter
The problem isn't there. It send the correct value to the adminClientInfoPolicy(id) function in the 6'th post. It throws away the zero's when I do this in that function
Code: Select all
document.formname.IDNumber.value=id;
document.formname.submit();
Posted: Thu Jun 10, 2004 4:51 am
by Zooter
Hi, Me again. This solution works fine, except for when I have numbers and characters that I want to post as IDNumber,ie. E1234. If I want to post this, I get an error saying that 'E1234' is undefined, with code 0. My guess is that it has something to do with the ASP function.
Anyone any solution?