Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
$press=$_GET['sell'];
echo $press; //OUTPUT IS : SELL
if($press == SELL)
{
header("Location: home.php");
}
You forgot a single/double quotation
if($press=='SELL')
on the other hand, you must not send any output such as echo before header. So, do not echo anything before header.
You forgot single quote
if($press == 'SELL')
{
header("Location: home.php");
}
You have to put SELL in quotes like 'SELL'
You must not output anything before you send any headers
Do like this.. Enclose the SELL under single quotes.
This works if your URL is in the format like .. http://yourwebsite.com/yourfile.php?sell=SELL
<?php
$press=$_GET['sell'];
if($press == 'SELL')
{
header("Location: home.php");
}
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
remove
echo $press; OUTPUT IS : SELL
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 10 months ago.
Improve this question
Hello there I have a php foreach loop running that is all working except one part. I am pulling in data from a local json file. The beginning foreach call looks like this:
<?php foreach($boatslips as $boatslip): ?>
One of the json fields is: "rent_sale_or_both" : "rent" (but that field can be rent, sale, or both,)
Lower down in the code after some other fields are successfully rendered and inside the foreach loop still i'm trying the below code to render out whether a boat slip is for rent, sale or both; and wanting to then be able to style 'rent' 'sale' or 'both' with css eventually.
<?php
if ($boatslip->rent_sale_or_both == rent) {
echo "rent";
}elseif ($boatslip->rent_sale_or_both == sale) {
echo "sale";
}else {
echo "both";
}
?>
Then some more html after the elseif.
At the end of the for each loop it is closed off properly with <?php endforeach; ?>
Obviously this is probably not correct? I think I'm making it harder than it is?
Any thoughts?
You might be missing a couple of quotation marks.
$boatslip->rent_sale_or_both == "rent"
$boatslip->rent_sale_or_both == "sale"
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I wrote a little check to display succes messages whenever a form is validated succesfully. However the check I use doesn't work. it doesn't matter what $_GET['info'] is, it just shows all messages unless $_GET['info] is empty. so even when info = loggin it shows all three messages. any help?
if(!empty($_GET['info'])){
if($_GET['info'] == "succes-paid"){
echo "<p class='succes'>De bestelling/inschrijving is succesvol verlopen.</p>";
}
if($_GET['info'] == "succes-register"){
echo "<p class='succes'>U werd succesvol geregistreerd.</p>";
}
if($_GET['info'] == "login"){
echo "<p class='succes'>U werd succesvol ingelogd.</p>";
}
}
You have a semi-colon after each of your if statements. The semi-colon means "finish the statement". Therefore your program thinks that you are done with the if and everything in your braces is treated as a block separate from your if statement. That is why those blocks are always executing.
It's because of the semicolon right after the condition of the if.
That line is actually two statements. The first is the if with condition, followed by an 'empty' statement, ended by a semi-colon. The second is a compound statement (a block of statements within a set of { .. }. The compound statement doesn't have a condition at all, so it is always executed.
if($_GET['info'] == "succes-paid") ; {echo 'x'}
condition with no statement -----^ ^ ^--------^-- compound statement without condition
\_The semi-colon that separates them.
And you have this situation three times, hence three lines of output.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am reviewing a website that was designed years ago. There is a problem on the contact page
that spits an error:
Parse error: syntax error, unexpected T_LNUMBER in /home/content/p/r/e/prentexaf1/html/contact.php on line 61
Line 61 is that which starts: print"meta...
Here is the entire function around it:
function redirectTo($to) {
$url = $to;
print "<html><head><script> location.href='$url'¥n </script>";
print "<meta HTTP-EQUIV=Refresh CONTENT=¥"0; URL=$url¥">";
print "</head><body>If you see this page, click here to continue</body>";
print "</html>";
exit;
}
I'm unfamiliar with php enough not to know what problem is happening here (I did not write this function, just am trying to solve the error for a friend that owns the site [also didn't write it]). I've looked up the meta tag info. My instincts says this is an issue following content but that's just a hunch. Please advise..
Thank you in advance!
Some of the double quotes needed to be escaped. (Besides the funky ¥ characters which have been removed)
function redirectTo($to) {
$url = $to;
print "<html><head><script>location.href='$url'</script>";
print "<meta HTTP-EQUIV=Refresh CONTENT=\"0; URL=$url\">";
print "</head><body>If you see this page, click here to continue</body>";
print "</html>";
exit;
}
they (quotes) might have been accidently replaced with that character, using a Word processor of sorts.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have a very simple php script designed to test the function htmlspecialchars:
$question="<script>alert('hacked')</script>";
echo "<br>original question=",$question;
$question = make_secure( $question );
echo "<br>converted question=",$question;
echo "<br>converted question calling htmlspecialchars=",htmlspecialchars($question);
function make_secure($data) {
$data = htmlspecialchars($data); return $data; }
It should remove the special chars from the original string $question by calling a function with htmlspecialchars inside it. However, the function does not seem remove the special chars. They are only removed if I call htmlspecialchars explicitly in the script. Why?
Thanks.
EDIT: This is what I see when I run the script:
original question=
converted question=<script>alert('hacked')</script>
converted question calling htmlspecialchars=<script>alert('hacked')</script>
(the 'hacked' script is also executed first). To rephrase my question, why is the script still perfectly visible in $question on line line converted question= ? i.e. why hasn't the variable been converted? I thought that after the variable had been converted, the script should no longer be visible.
The output visible to the user should be:
(nothing, script executed)
<script>alert('hacked')</script>
<script>alert('hacked')</script>
The actual output, visible to the browser is:
<script>alert('hacked')</script>
<script>alert('hacked')</script>
<script>alert('hacked')</script>
Which is exactly correct. The first line is unescaped, the HTML and script get interpreted. The second line is escaped once, displaying the text as is to the user. The third line is escaped twice, displaying the text as escaped once to the user.
You keep escaping the same variable over and over, so the result is going to change depending on how often you escape it. Maybe start here: The Great Escapism (Or: What You Need To Know To Work With Text Within Text)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have in a foreach loop:
echo "<span style=\"" . myCss($value) . "\">lol</span>";
Which turns into (in source):
<span style="">lol</span>color: #999999;background-color: transparent;font-weight:normal;text-decoration: none;<span style="">...
Why? how to prevent the browser? Same for Chrome and Firefox. Note there is a reason for it being in-line, an I want to avoid doing it via javascript.
Try this
echo "<span style='" . myCss($value) . "'>lol</span>";
How about a little separation of PHP and HTML:
<span style="<?php echo myCss($value); ?>">lol</span>
Notice I encapsulate the PHP within the quotes, rather than echo the entire line. In a foreach loop it would look something like:
<?php
foreach($array as $key => $value){
?>
<span style="<?php echo myCss($value); ?>">lol</span>
<?php
}
?>
This separation of PHP and HTML has been the standard practice everywhere that I have worked, and I personally find it to be much more transparent.
Without seeing your function and the values of the variables, I an only assume that there are characters in the echoed result that mess up the html. You should always use htmlspecialschars() when you output to html:
echo "<span style=\"" . htmlspecialschars(myCss($value)) . "\">lol</span>";
Although you would probably use it in your function.