MyBB Community Forums

Full Version: PHP Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
You're not escaping any of the quotes within quotes.


For example:

<?php

echo("You said \"Hello!\" Yep. ^_^");

?>

See? Whenever you do not escape a quote PHP thinks you're closing the statement.

So what you wanna do is this:

<?php
if($_GET['m'] == "1") {
echo "<embed src=\"movies/service_announcement.mov\" width=\"320\" height=\"256\" controller=\"true\" autoplay=\"true\" pluginspage=\"http://www.apple.com/quicktime/download/\" type=\"video/quicktime\"></embed>";
} elseif($_GET['m'] == "2") {
echo "<embed src=\"movies/photo_montage.mov\" width=\"320\" height=\"256\" controller=\"true\" autoplay=\"true\" pluginspage=\"http://www.apple.com/quicktime/download/\" type=\"video/quicktime\"></embed>";
}elseif($_GET['m'] == "3") {
echo "<embed src=\"movies/retro_yearbook.mov\" width=\"320\" height=\"256\" controller=\"true\" autoplay=\"true\" pluginspage=\"http://www.apple.com/quicktime/download/\" type=\"video/quicktime\"></embed>";
}elseif($_GET['m'] == "4") {
echo "<embed src=\"movies/service_announcement2.mov\" width=\"320\" height=\"256\" controller=\"true\" autoplay=\"true\" pluginspage=\"http://www.apple.com/quicktime/download/\" type=\"video/quicktime\"></embed>";
}elseif($_GET['m'] == "5") {
echo "<embed src=\"movies/mm_transfer.mov\" width=\"320\" height=\"256\" controller=\"true\" autoplay=\"true\" pluginspage=\"http://www.apple.com/quicktime/download/\" type=\"video/quicktime\"></embed>";
}else{
echo "<table border=\"1\" bordercolor=\"#FFFFFF\" width=\"320\" height=\"256\" cellpadding=\"0\" cellspacing=\"0\"><tr><td><center>No Movie Was Specified<center></td></tr></table>";
}
?>

That should work fine.
Ohhhhhhh!!!! I get it! Thank you again! Thank You all for being a huge help!
Ryan, just out of curiousity, is there any reason he couldn't just use single quotes there?

echo '<embed src="whatever">';

I mean, escaping your quotes is a good habit to get into, but just for simplicity sake since he's not using any variables inside echo(); it'd be easier to use single-quotes. Just curious if there's a specific reason why escaping is the better option here.
Okay, i have another php question. i have been trying to make a hit counter, and the script i have works sometimes, other times, it comes up with errors.
<?php 
$c_ip = $HTTP_COOKIE_VARS["user_ip"];
$counter_file = "scripts/count.txt";
$counter_file_line = file($counter_file);  if(!$c_ip) {
setcookie("user_ip", $REMOTE_ADDR, time()+360000);  $counter_file_line[0]++; 
$cf = fopen($counter_file, "w+");
fputs($cf, "$counter_file_line[0]");  fclose($cf); 
} 
elseif($c_ip != $REMOTE_ADDR){
$counter_file_line[0]++;   $cf = fopen($counter_file, "w+");
fputs($cf, "$counter_file_line[0]");
 fclose($cf);
}
echo $counter_file_line[0];
?>
This script is supposed to make a hit counter that is unique based on cookies, which is what i am looking, for, but this pops up sometimes:
Warning: Cannot modify header information - headers already sent by (output started at /home/content/e/z/e/ezevolk/html/volkshowcase/index.php:5) in /home/content/e/z/e/ezevolk/html/volkshowcase/index.php on line 106
or
Warning: file(scripts/count.txt): failed to open stream: No such file or directory in /home/content/e/z/e/ezevolk/html/volkshowcase/movies/index.php on line 116

Warning: Cannot modify header information - headers already sent by (output started at /home/content/e/z/e/ezevolk/html/volkshowcase/movies/index.php:5) in /home/content/e/z/e/ezevolk/html/volkshowcase/movies/index.php on line 117

Warning: fopen(scripts/count.txt): failed to open stream: No such file or directory in /home/content/e/z/e/ezevolk/html/volkshowcase/movies/index.php on line 118

Warning: fputs(): supplied argument is not a valid stream resource in /home/content/e/z/e/ezevolk/html/volkshowcase/movies/index.php on line 119

Warning: fclose(): supplied argument is not a valid stream resource in /home/content/e/z/e/ezevolk/html/volkshowcase/movies/index.php on line 119
The file location is correct, is something in the code incorrect?
Galen Wrote:Ryan, just out of curiousity, is there any reason he couldn't just use single quotes there?

echo '<embed src="whatever">';

I mean, escaping your quotes is a good habit to get into, but just for simplicity sake since he's not using any variables inside echo(); it'd be easier to use single-quotes. Just curious if there's a specific reason why escaping is the better option here.
Only thing with ' quotes is that you can't use a $ var inside of them.
Some like using quotes anyways.
EZE Wrote:Okay, i have another php question. i have been trying to make a hit counter, and the script i have works sometimes, other times, it comes up with errors.
CODE
This script is supposed to make a hit counter that is unique based on cookies, which is what i am looking, for, but this pops up sometimes:
Warning: Cannot modify header information - headers already sent by (output started at /home/content/e/z/e/ezevolk/html/volkshowcase/index.php:5) in /home/content/e/z/e/ezevolk/html/volkshowcase/index.php on line 106
or
Warning: file(scripts/count.txt): failed to open stream: No such file or directory in /home/content/e/z/e/ezevolk/html/volkshowcase/movies/index.php on line 116

Warning: Cannot modify header information - headers already sent by (output started at /home/content/e/z/e/ezevolk/html/volkshowcase/movies/index.php:5) in /home/content/e/z/e/ezevolk/html/volkshowcase/movies/index.php on line 117

Warning: fopen(scripts/count.txt): failed to open stream: No such file or directory in /home/content/e/z/e/ezevolk/html/volkshowcase/movies/index.php on line 118

Warning: fputs(): supplied argument is not a valid stream resource in /home/content/e/z/e/ezevolk/html/volkshowcase/movies/index.php on line 119

Warning: fclose(): supplied argument is not a valid stream resource in /home/content/e/z/e/ezevolk/html/volkshowcase/movies/index.php on line 119
The file location is correct, is something in the code incorrect?
make sure scripts/count.txt is a file, in the scripts folder in a folder inside the root of your page.
To fix the "cannot modify header information" error, you must put that piece of code at the very top of your .php page. There must be no output that comes out before the set_cookie call (even a space or a line break is not allowed).
Okay, I see. Also, just to clarify (I'm not trying to be rude when I say this.) I am very new to PHP, so although these problems may be very simple to everyone, but I do not always understand what is wrong, because I am still learning PHP(I am very fluent in HTML and CSS though). If I am annoying anyone with my questions, or in general, I am sorry and I will stop.
I don't know if you misinterpreted my tone: I used the bolds to emphasize certain points (the important points) of my post. In no way am I discouraging or not welcoming you from asking questions here. If you have any questions about what I posted, feel free to ask.
I did not miss-interpret your tone, i was just making sure people understood that I was quite new at php. However, i have a javascript question now. I know how to make a alert, but what is the code for a alert with a "OK" and "Cancel" option? Like for the pop-up for a new private message? I searched through the mybb files on my server, but i could not find the script, does anyone have it memorized?
I think the function confirm() is the one you're looking for: http://www.tizag.com/javascriptT/javascriptconfirm.php
Pages: 1 2 3 4 5