itsjareds Posted June 16, 2008 Share Posted June 16, 2008 Hi, I need to write a page that uses queries in the url like example.com/example.php?thisiswhatiwant=2 If there is no question mark, I want it to display an alert box asking "What would you like this variable to be?" If there is something after the question mark, I want it to add what the variable is here: <PARAM value="[color=red]query_variable[/color]"> I tried to do something similar with javascript that worked like this: <head> <script type="text/javascript"> function getName() { var name = prompt("What is the title name of your picture?","Enter name here"); if (name!=null && name!="") { return name; } } </script> </head> <body> <applet> <PARAM value="<script type="text/javascript">document.write("getName()");</script>"> </applet> </body> I've written in PHP but it was so long ago, and I can't remember anything. Any help? Link to comment https://forums.phpfreaks.com/topic/110360-how-to-use-query-strings-in-html/ Share on other sites More sharing options...
Styles2304 Posted June 16, 2008 Share Posted June 16, 2008 I don't really have enough info to answer this question all the way but what I would do is is pass the variable through the URL regardless then just check to see if it has been set : "http:www.url.com?variable=xxx" <?php if (!isset($_GET['variable'])) { //whatever you want to happen if the variable isn't set. } else { //whatever you want to happen if the variable IS set such as checking for certain values. } ?> hope that helps . . . sorry if it doesn't. Link to comment https://forums.phpfreaks.com/topic/110360-how-to-use-query-strings-in-html/#findComment-566243 Share on other sites More sharing options...
itsjareds Posted June 16, 2008 Author Share Posted June 16, 2008 Ok, that helped some, so I tried writing with your code. This is what I have so far: Notice that I'm not sure what needs to be escaped, so I played it safe.. <?php if (!isset($_GET['pic'])) { echo "<script type='text/javascript'> function getName() \{ var name = prompt(\'What is the title name of your picture\?\',\'Enter name here\')\; if (name!=null && name!=\'\')\{ window.location.href = window.location.href + \'?pic=\' + pic\; \} \}"; ?> <head> </head> <body> <applet> <param ... > <?php echo "<PARAM NAME='GALLERY_PIC' VALUE='". $pic ."'>"; ?> </applet> </body> I get an error that says Parse error: syntax error, unexpected $end in /home/myhomepage on line 62. The problem is I can't find any missed closing tags or anything ??? Link to comment https://forums.phpfreaks.com/topic/110360-how-to-use-query-strings-in-html/#findComment-566272 Share on other sites More sharing options...
itsjareds Posted June 16, 2008 Author Share Posted June 16, 2008 Woo! Nevermind, I figured it out Here's my code <head> <?php if (!isset($_GET['pic'])) { echo "<script type=\"text/javascript\"> var name = prompt('What is the title name of your picture?','Enter name here'); if (name!=null && name!='') { window.location.href = window.location.href + \"?pic=\" + name; } else { name = \"invalid\"; window.location.href = window.location.href + \"?pic=\" + name; } </script>"; } ?> </head> <body> <applet> <param .... > <?php echo "<PARAM VALUE='". $pic ."'>"; ?> </applet> </body> Lots of php coming back to me now Link to comment https://forums.phpfreaks.com/topic/110360-how-to-use-query-strings-in-html/#findComment-566279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.