Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Having trouble passing a parameter through a button, php

New Here ,
Feb 08, 2010 Feb 08, 2010

Hello all,

I'm new to the forum and to web design and Dreamweaver, please go a little easy on me!

I'm currently in the process of making a fantasy football website in Dreamweaver and phpmyadmin. When a user visits the site and wants to enter the competition they click register which brings up the register page. There they can fill out the form containing details username, password etc. When they click the register button at the bottom of the form their details are put into the users table in the database and they are passed onto the next page where they are asked to pick their team. The team details are kept in a seperate table in the database.

What i'm trying to do is pass the username that is created in the register form to the pick team page as a parameter.

Currently the code for my button is as follows:

<input type="submit" value="Insert record" />

and the sql for after insert goto is currently?

$insertGoTo = "pickteam.php";

In another section of the site i have passed a parameter with a link as follows:


<a href="editgoalkeeper.php?gkid_gk=<?php echo $row_rs_viewgks['gkid_gk'];?>">

but i'm not sure how to pass a parameter using a submit button, can anyone help me please?

TOPICS
Server side applications
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 09, 2010 Feb 09, 2010

You need to use PHP sessions, and store the username as a session variable.

Begin the page that registers the user with session_start();. You can then save the username to a session variable:

session_start();

if (isset ($_POST['username'])) {

  $_SESSION['username'] = $_POST['username'];

}

Thereafter, $_SESSION['username'] will be available on any page that begins with session_start();.

Translate
LEGEND ,
Feb 08, 2010 Feb 08, 2010

You pass a parameter by putting the value you want to pass into a form field.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 08, 2010 Feb 08, 2010

Please pardon my ignorance, i'm still very new to web development and Dreamweaver.

Please could you give me an example of how i would go about coding the above?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 08, 2010 Feb 08, 2010

I don't do php so I'm not sure if the reference to the dynamic data is correct, but it would be something like:

<form action="editgoalkeeper.php" method="get">
<input name="GoalKeeperID" type="text" value= <?php echo $row_rs_viewgks['gkid_gk'];?>>
<input name="submit" type="submit">
</form>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 09, 2010 Feb 09, 2010

pb1uk wrote:

but i'm not sure how to pass a parameter using a submit button, can anyone help me please?

You can't pass a parameter using a submit button. If the value is not something that the user inserts into the form, you need to pass the value as a hidden field.

<input type="hidden" name="some_value" id="some_value"

  value="This will be passed with the form when submitted" />

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 09, 2010 Feb 09, 2010

Hi,

Sorry i don't think i've explained it well.

The user is filling out a form to register as a user. Part of the form requires them to enter their username. After completing the form the users details are enterred into the database and they go onto the next page requiring the user to pick their team. This page is like another insert record form as it will insert a record into the teams table of the database.

What i need to do is have the value the user enterred into the username field in the register form passed to the pick team page. This is because a users details and their teams details are held in different tables. So the username is a foreign key in the team table.

Hope that makes sense

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 09, 2010 Feb 09, 2010

You need to use PHP sessions, and store the username as a session variable.

Begin the page that registers the user with session_start();. You can then save the username to a session variable:

session_start();

if (isset ($_POST['username'])) {

  $_SESSION['username'] = $_POST['username'];

}

Thereafter, $_SESSION['username'] will be available on any page that begins with session_start();.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 09, 2010 Feb 09, 2010

Thanks David.

If i were to do that approach would i need to put that code at the top of every page on the site, or just when a user logs in.

As the register page is only a simple record form insertion wizard page would adding this code mean a user is actually logged in. At the moment after registering the user has to go back to the main page and login and the register page doesn't log them in, if that makes sense

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 09, 2010 Feb 09, 2010
LATEST

See the following page in the FAQ: http://forums.adobe.com/thread/417437.

When someone logs in, the username is automatically stored in $_SESSION['MM_Username'].

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines