1

I am trying to pass three parameters from one php file to another. Two of those parameters are in variables that are already determined long before the button is clicked to call the second php file, but one will be taken from a text box at the time the button is clicked.

So far I have the following (snippet) in the first php file. The two parameters that are in the existing variables show up in the URL just fine, but I can't figure out how to get the student number to be included. The URL just has "studentNumber=?&club=..."

Thanks!

   <input type="text" id="studentNum" placeholder="Student Number">
   <input type="button" value="Add Student" onclick="window.location = '<?php $url = 'http://npapps.peelschools.org/editor/add.php?studentNumber='.$_GET["StudentNum"].'&club='.$club.'&type='.$type.''; echo $url;?>'" />
P. D. Brown
  • 53
  • 1
  • 4

4 Answers4

0

If you use $_GET["StudentNum"], it must come from an HTML-form or a html-link:

<a href="form.html?StudentNum=1337">example</a>

or

<form method="GET"><input name="StudentNum" value="1337"></form>

Good luck

Cagy79
  • 1,610
  • 1
  • 19
  • 25
0

The URL of your current page needs to have had studentNum present as a query parameter to be able to use $_GET. For example, if current page URL =

http://npapps.peelschools.org/myotherpage.php?studentNum=100

then you can $_GET["studentNum"]. Also, if you are accessing this URL via ajax

http://npapps.peelschools.org/myotherpage.php

then it must be passed as a data parameter.

Find out what the URL of the page is where you have the HTML that you have shown, and if studentNum has not been passed as a query parameter or data parameter from however you get there (e.g. an anchor tag href) then add that parameter to the URL.

0

Is it really necessary to use window.location? I would encourage you to use something like this

function doSubmit() {
  document.getElementById("myformid").submit();
}
<form id="myformid" action="receivingPHP.php" method="POST">
  <input id="studentnr" type="text" value="42" />
  <button onclick="doSubmit()">Send</button>
</form>

Of course there is no receivingPHP.php file on the StackOverflow servers, so if you try this script you will reach a white page (close it in the top right corner where it says close)

DBX12
  • 2,041
  • 1
  • 15
  • 25
0

Ended up reworking it so that all the information was sent in a form rather than trying to embed it in a button. The secret came from w3schools where I figured out how to hide the known parameters in a hidden input element in the form, as follows:

<form action="add.php" method="GET">
     <input name="studentNo" type="text" placeholder="Student Number"  />
     <input name="club" type="hidden" value="<?php echo htmlspecialchars($club); ?>" />
     <input name="type" type="hidden" value="<?php echo htmlspecialchars($type); ?>" />
     <input type="submit" value="Add Student" />
</form>
P. D. Brown
  • 53
  • 1
  • 4