homepage Welcome to WebmasterWorld Guest from 54.166.116.36
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP/SQL pass value to field on linked page
thirdphase

5+ Year Member



 
Msg#: 7445 posted 11:03 am on Mar 22, 2005 (gmt 0)

Sorry if this has been asked before (I did do a search first!)

I have setup an sql table containing project data (job no, description, date and auto-number id) which displays in rows on my main page. Next to each project is a link which a user can click to submit their details to show interest in that particular project. When they click this link they are taken to another page with a contact form, but I need to automatically show the job no of the project they selected in this form. I have successfully got the job no for the 1st record in the table into the field but need to make it dynamic.

How do I get the correct job no according to the link they click?

Thanks.

 

copongcopong

10+ Year Member



 
Msg#: 7445 posted 11:55 am on Mar 22, 2005 (gmt 0)

it appears you need to pass some data in the actual link. You can accomplish this by passing arguments on the link like ...

newpage.php?var=1&row=2

then on the newpage.php, add code that would check for the value of the query string using $_GET; e.g. $_GET['var'] and $_GET['row'] from here you can add your script on what you want to do with the data passed on the link.

gardenguy

5+ Year Member



 
Msg#: 7445 posted 11:56 am on Mar 22, 2005 (gmt 0)

By $_GET or $_POST on your receiving page, depending on the METHOD you used on your selection form.
In the form SELECT you need to assign a name to the value selected, then GET it on the next page.

wildeyedfrank

5+ Year Member



 
Msg#: 7445 posted 12:02 pm on Mar 22, 2005 (gmt 0)

When I generate the link, I append the variables to the end of the URL after a delimiter of some kind. (I use 2 backticks) Then I pull the URL on the following page, and get out that information.

Here is what your hyperlink would look like
mysite/cat_page.php/``cat=1&col=1

At the beginning of the following page's code:

$vars = get_url_vars(); //my function
parse_str($vars); //php function
....................
then you can access $cat and $col in the code.

here is my declared function

function get_url_vars()
{
$temp_url = $_SERVER['PHP_SELF'];
$rip = explode('``',$temp_url);
return $rip[1];
}

It may not be the best way to do it, and certainly not the only way...but when I was there, this is how I solved the problem. (I also put in a check for control characters in the variables on each page...but I couldn't get any through anyway when I was testing)

thirdphase

5+ Year Member



 
Msg#: 7445 posted 1:21 pm on Mar 22, 2005 (gmt 0)

Thanks everyone! Very easy to follow - even for a newbie...

IT WORKS! YEAH

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved