Page 1 of 1
[SOLVED] html hyper links to send vars to php
Posted: Mon Nov 01, 2004 5:16 am
by fresh
hey, I can not think of a way to explain this besides showing you some syntax:
Code: Select all
<?php
//-------------------------
// mypage.php
//-------------------------
$w_name = $_POST['who']; //get which link they clicked
if($w_name != "") { //check to see if who var is empty
echo " You clicked the ".$w_name." link!";
} else {
echo "No name specified!"; //deny if who var empty
}
?>
<form action='http://mypage.php' method='post'>
<a href='#' name='who' onclick='javascript:submit()'>Todd</a>
<a href='#' name='who' onclick='javascript:submit()'>John</a>
<a href='#' name='who' onclick='javascript:submit()'>Bill</a>
</form>
I haven't tried doing this yet in any of my projects, so if someone could show me the proper syntax to accomplish the above therory, I would be much appreciative.. thanks

Posted: Mon Nov 01, 2004 6:23 am
by kettle_drum
You would need to create a field and value to be sent in the form with javascript before submitting.
Posted: Mon Nov 01, 2004 7:01 am
by fresh
well how does phpbb do it.. I mean if you goto memberslist and click a name it brings you to that users profile.. which is basically what I am trying to accomplish with links.. so that say some one clicks the link jason.. the user will be taken to mypage.php where Jason's info from the DB will be populated.. or if they click Bill, they will goto mypage.php where Bill's info from the DB will be poulated.. can a field be a link?? I just need to send the php script the users name and it will know where to look.. could someone show me an example.. thanks

Posted: Mon Nov 01, 2004 7:07 am
by phpScott
instead of just doing javascript:submit() do something like
Code: Select all
<script language="javascript">
function seeWho(name)
{
url='mypage.php?name='+name;
document.myform.action=url;
}
</script>
<form name='myform' id='myform' action='http://mypage.php' method='post'>
<a href='#' name='who' onclick='javascript:seeWho('todd')'>Todd</a>
<a href='#' name='who' onclick='javascript:seeWho('john)'>John</a>
<a href='#' name='who' onclick='javascript:seeWho('bill')'>Bill</a>
</form>
you will have to of course dynamically create the name in the function call.
Posted: Mon Nov 01, 2004 7:11 am
by fresh
dynamically create the name: do you mean whilst pulling them from the DB and writing the names to the page??
Posted: Mon Nov 01, 2004 7:52 am
by phpScott
yes. I am assuming that the list won't be fixed so you can't create it in just straight hmtl. If they are fixed then ignore me as I am just rambling.
How are you going to create the list of users that will be displayed?
Posted: Mon Nov 01, 2004 8:08 am
by kettle_drum
Arent the links to the users in phpbb just images inside of links? Dont see why you need to complicate things.
Posted: Mon Nov 01, 2004 8:09 am
by phpScott
sorry forgot you where going to be using phpbb.
never mind me.

Posted: Mon Nov 01, 2004 8:19 am
by patrikG
http://uk.php.net/FAQ.html
PHP Manual: first call when having questions about PHP.
Google: second call when having questions about PHP.
Search Function of this forum: : third call when having questions about PHP.
Posting a new message: fourth call when having questions about PHP
Click on the first link below for further details.
Posted: Mon Nov 01, 2004 7:30 pm
by fresh
hey no I was just using phpbb as an example.. and yes, I will be enumerating a list of names from my sql db.. I suppose I will try the javascript.. unless there is a php way of doing this.. I just think the less one sees the better off I will be.. thanks

Posted: Tue Nov 02, 2004 2:27 am
by irealms
I use something like this:
Code: Select all
<?php
//use a while loop to create a list of names
//put this link inside the while loop and $your variable can be pulled from
//the row
echo '<a href="mypage.php?userselect='.$yourvariable.'" />Link to page</a>';
//on the page where you need it to show the right profile
if (isset($_GET['userselect']))
{
$selectuser = "SELECT * FROM usertable WHERE user='$_GET[userselect]'";
@mysql_query($selectuser, $connect);
}
else
{
//the pages usual code
}
?>
At least this is what i usually do, unless i'm not following what your getting at.
Posted: Tue Nov 02, 2004 6:18 am
by fresh
thats what I was looking for, something like that.. thanks alot

Posted: Tue Nov 02, 2004 6:28 am
by patrikG
fresh wrote:hey no I was just using phpbb as an example.. and yes, I will be enumerating a list of names from my sql db.. I suppose I will try the javascript.. unless there is a php way of doing this.. I just think the less one sees the better off I will be.. thanks

If you follow the link I posted and read the link, you'll understand that this is one of the most frequently asked questions. The PHP manual has dedicated an entire page just to that. So, I'd advise you to read:
http://uk.php.net/FAQ.html