session variable gets value when clocked on url

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

Post Reply
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

session variable gets value when clocked on url

Post 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
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post 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.
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post by Zooter »

Thanks I will try that. Let you know what happens.

Cheers
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post 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>&nbsp;</td>
<td><font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
</tr>
<?php } ?>
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Please read this before making any more posts

viewtopic.php?t=21171

Thanks

Mark
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

Change the href to:

Code: Select all

javascript:adminClientInfoPolicy("<?=$row&#1111;"IDNumber"];?>");
then add a function to the page that will do the form-based stuff:

Code: Select all

<script language="javascript>
function adminClientInfoPolicy(id) &#123;
    document.formname.IDNumber.value=id;
    document.formname.submit();
&#125;
</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...
Last edited by dave420 on Tue May 18, 2004 11:40 am, edited 1 time in total.
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post by Zooter »

Thanks for the help
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post by Zooter »

Thanks alot. It worked...
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post by Zooter »

This hyperlink works now. Another problem is now one of leading zero's being thrown away by the function...

The value of

Code: Select all

<?=row["IDNumber"];
?>
in

Code: Select all

javascript:adminClientInfoPolicy("&lt;?=$row&#1111;"IDNumber"];?&gt;");
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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

is it always 10 digits?

<?= sprintf("%010d",$row['IDNumber']); ?>
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post 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();
Zooter
Forum Commoner
Posts: 45
Joined: Tue May 18, 2004 10:46 am
Location: South Africa

Post 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?
Post Reply