-6

I have some error in my PHP contact form

   if ($sukces){
      print "<meta http-equiv="\" refresh\""="" content="\" 0;url="potwierdzenie.php\""">";
      }
    else {
       print "<meta http-equiv="\" refresh\""="" content="\" 0;url="error.htm\""">";
}
?>

I know it's something with \ should be / but I have no idea where. Thanks for help.

Quzziy
  • 65
  • 2
  • 11
  • 3
    Get rid of all the escaped quotes. Instead use single quoted strings inside the outer double quoted one. `print "";` – Michael Berkowski Dec 19 '14 at 23:34
  • 2
    Even SO's built-in syntax highlighter shows the problem ;) – fejese Dec 19 '14 at 23:34
  • Backslash-escaping quotes should not be necessary all that often, unless you are trying to embed JavaScript into output from PHP. Usually you will be able to use double on the outer string (if you have `$variables` to interpolate inside) and single inside, or single on the outer string and double inside. – Michael Berkowski Dec 19 '14 at 23:36
  • @Michael Berkowski Now it's working like a spam :) – Quzziy Dec 19 '14 at 23:54
  • @MichaelBerkowski I thought to post it as an answer because it seems to be the answer here, but afterall, it is was your point and I apologize for posting. Answer deleted. – Nick Louloudakis Dec 19 '14 at 23:56
  • @NickL. I voted to undelete your answer. You should undelete it and I'll upvote it. I commented rather than answer because it is likely this question will eventually be deleted - it's already been put on hold. – Michael Berkowski Dec 20 '14 at 00:44
  • Ok, I just did it. And again, thank you and I apologize for posting it instead of you. – Nick Louloudakis Dec 20 '14 at 00:48
  • @NickL. No apology necessary. I would have answered if I wanted to. – Michael Berkowski Dec 20 '14 at 00:48

2 Answers2

3

You have several options:

1) Escape like this:

echo "<meta http-equiv=\"Refresh\" CONTENT=\"0\"; URL=\"potwierdzenie.php\">";

2) Use the embedded syntax of if-else in HTML:

<?php if ($sukces): ?>

<meta http-equiv="Refresh" CONTENT="0" URL="potwierdzenie.php">
<?php else:   ?>    
<meta http-equiv="Refresh" CONTENT="0" URL="error.htm">
<?php endif; ?>

If else embedding inside html

3) Use single quotes inside double quotes as @"Nick L." said

4) Do this:

< meta http-equiv="Refresh" CONTENT="0" URL="< ?= ($sukces ? "potwierdzenie.php" : "error.htm" ) ? >">

Community
  • 1
  • 1
boctulus
  • 404
  • 9
  • 15
1

A good way to avoid this mess is to use single quotes (as mentioned in the comments, kudos to Michael Berkowski's comment):

<?php

if ($sukces){
      print "<meta http-equiv='refresh' content='0' url='potwierdzenie.php'>";
} else {
       print "<meta http-equiv=' refresh' content='0'url='error.htm'>";
}

?>
Nick Louloudakis
  • 5,856
  • 4
  • 41
  • 54