1

I am making a SQL table viewing page through PHP, and I am trying to create popup windows through links in the table. I have a php variable $formID I am making a popup window by echoing a javascript script, like

echo "<td style='border:1px solid black;'>'<script type=\'text/javascript\'>window.open(\'awards.php?formID\',\'Window1\',
\'menubar=no,width=430,height=360,toolbar=no\');</script>'</td>";

would that pass $formID to awards.PHP or am i doing it wrong?

3
  • 1
    is there a missing ( after window.open? Commented Sep 15, 2012 at 18:15
  • and & will give you syntax errors. Commented Sep 15, 2012 at 18:16
  • @sachleen I copypasted this code from a tutorial and I'm trying to make it fit my needs, fixed that as well Commented Sep 15, 2012 at 18:17

3 Answers 3

2

awards.php?formID this will not the pass form id since php does not recognize it as a variable and replace with its value . Use the awards.php?form_id={$formID}

you recieve the variable like $getformID = $_GET['form_id'];

Sign up to request clarification or add additional context in comments.

1 Comment

and from awards.php do i recieve the variable like $formID = $_GET['formID']; ?
0

Try this:

echo '<td style="border: 1px solid black;"><script type="text/javascript">window.open(\'awards.php?formID='.urlencode($formID).'\', \'Window1\', \'menubar=no,width=430,height=360,toolbar=no\');</script></td>';

From awards.php you can get it like this:

$formID = urldecode($_GET['formID']);

Comments

0
echo "<td style='border:1px solid black;'><script type='text/javascript'>window.open('awards.php?formID={$formID}','Window1','menubar=no,width=430,height=360,toolbar=no');</script></td>";

That will probably work. Then on your other page, get the value with $_GET['formID'].

You don't need to escape the single quotes because they're all in a set of double quotes. You only need to do that if you're nesting quotes of the same kind.

You could also do something like this:

"part of your string " . $formID . " rest of my string";

or

"part of your string {$formID} rest of my string."

More info on this Complex (curly) syntax

1 Comment

It's possible to embed PHP variables inside a string directly, like: "part of your string $formID rest of my string". The curly braces syntax is handy if you want to embed a variable that is an element of an array or a member of an object, i.e: "part of your string {$this->formId} rest of my string"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.