First things first, welcome to PHP and the PHP Developers Network Forums. Here are a few recommendations...
1) Use complete tags (<?php)instead of short tags (<?) for opening your PHP code. There is a possibility that someday short tags may not be supported and your code would have to be rewritten. Worse yet, your host may not support short tags in their PHP installation, which would result in you having to rewrite your code.
2) You can use echo parallel to print. So your title, for example, could be written as...
3) As for your echoing of the link structure, you could do it just like you have. The ampersand between the variable is just your querystring separator. The semicolon is PHP's way of ending a line of code.
Hope that helps. And, again, welcome to the forums.
<a href="qtdisplay.php?movie=<?php echo=$911.mov; ?>&title=<?php echo=$Title; ?>;">to watch movie click here</a>
I’m placing this code in my wordpress post template so all I need to do is change the variables. But it’s not working and I think I know why.
html is thinking the “>” is the end of its tag when in all actuality it’s the end of the PHP tag. How can I get around this? I think there is an escape character but I don’t remember what it is. Do you think an escape character will fix the problem?
I may need to do this all with javascripting, which is how I was doing it on the windows box. I just wanted to avoid the extra step.
it's not working for several reasons. First, the = after each echo shouldn't be there. Second, '.mov' will be processed wrong. Read up on how strings work here: http://php.net/language.types.string
When run through the parser, the PHP gets processed then applied to the HTML, so it wouldn't get confused. One thing that will cause you some issue is the .mov part added to your $911 var, which is also incorrect. You cannot start a vaiable name with a number (only alpha chars and underscores). You may need to echo the movie name variable and add the .mov part after the closing PHP tag.
I appreciate all the feedback. It looks like there is a fairly decent learning curve switching from asp. I think I'm up to it though... especially with this active forum.
It looks like WordPress is getting confused with the php.
this is before the code.
<?php
$moviename = '911.mov';
$title = 'Title';
?>
<a href="qtdisplay.php?movie=<?php echo $moviename; ?>.mov&title=<?php echo $title; ?>">to watch movie click here</a>
This is after the code.
I'm thinking I may need to define a JavaScript popup function to accept the variables and call the php from there... which is how I did it with ASP... but I was trying to avoid that step in the interest of efficiency.
dakev wrote:It looks like WordPress is getting confused with the php.
Actually, when you add code to a post in WordPress it gets parsed out, meaning the code will not execute in the display. If you want the link to appear normal in the posting, you should just reference it within the post itself, ie...
<a href="qtdisplay.php?movie=911.mov&title=Title">to watch movie click here</a>
If you had register_globals set to on, your first code would have worked. But it is better to leave them off, so doing it this way is a lot safer. I would also recommend some input validation, but start with this and see if it works.