2

I'm trying to build a SQL statement using variables that were posted on a previous page (show the SQL statement for copy-pasting in a div using echo), however, the one statement is preventing me from doing it.

<?php
    if (isset($_POST['locationName'])) {
        echo $_POST['locationName'];
    }
?>

As soon as I've put that in, the page refuses to load. It doesn't make any sense to me as I've got similar code throughout the page for the other input fields (to repopulate them after form submission).

As an exmaple: this works perfectly:

<input type="checkbox" name="lead" value="1" <?php if(isset($_POST['lead'])) echo "checked='checked'"; ?> />Lead Required<br>

I've been trying to change the quote types, and tried using htmlspecialchars as well as htmlentities in the echo, but each time I leave the in statement in, it breaks the page.

As soon as I comment that if statement out, the page loads again.

Here's the input field for the $_POST['locationName'] value:

<input required autofocus type="text" pattern="[a-zA-Z0-9-'\s\!\@\*]+" name="locationName" maxlength="100" size="67" placeholder="Place Name" value="<?php echo isset($_POST['locationName']) ? $_POST['locationName'] : '' ?>" />
Jim
  • 1,461
  • 1
  • 10
  • 15
  • Any errors in the PHP error log? – Barmar Oct 21 '15 at 10:49
  • 1
    @Barmar: No idea on how to view that – Jim Oct 21 '15 at 10:51
  • Well, I suggest you figure it out. You can't effectively debug scripts if you can't view the error messages. – Barmar Oct 21 '15 at 10:52
  • @Daan full code is over 300 lines... – Jim Oct 21 '15 at 10:52
  • What is "breaking the page"? What exactly happens? No output? If there's no output, your `if` statement is evaluating false. If other stuff, please tell. Show us relevant code to simulate your problem. – al'ein Oct 21 '15 at 10:53
  • Well this a problem we can't reproduce you need to give more information. – Daan Oct 21 '15 at 10:54
  • @AlanMachado View Source shows nothing at all. - If i remove that IF, then the page loads as it's meant to. – Jim Oct 21 '15 at 10:55
  • 2
    It's clear for me, then, that you're receiving some kind of PHP error but your error_display is disabled. Try to [enable](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) it and try again. – al'ein Oct 21 '15 at 10:55
  • Thanks @AlanMachado I'll give it a shot – Jim Oct 21 '15 at 11:02
  • Ok, I've managed to get some more info... using firebug, I go to the "Net" section and it reports a "500 Internal Server Error". What breaks _me_ is that it's that If statement that's doing it somehow. The PHP error log not even being run because of the 500... – Jim Oct 21 '15 at 11:18
  • Are you sure that locationName is a string and not an array? – Codrutz Codrutz Oct 21 '15 at 11:21
  • @CodrutzCodrutz i'm 99.8% certain. I'm adding the input field from the form in the post above. (really hope the 0.2% doesn't shine through again)... – Jim Oct 21 '15 at 11:23
  • Did you enabled error display? – al'ein Oct 21 '15 at 11:30
  • does `` not need a semi-colon to terminate it, i.e. `` – gabe3886 Oct 21 '15 at 11:31
  • @gabe3886 It doesn't seem to make a difference - I added the semi colon and the if statement still breaks it. while commenting the if statement out, lets the rest of the page load again. – Jim Oct 21 '15 at 11:35
  • @AlanMachado Yes I did, but because it's generating a 500 Internal Server Error somehow, nothing is being run on that page. – Jim Oct 21 '15 at 11:36
  • Is it apache? If it is, go to your apache log errors on apache root folder/logs – al'ein Oct 21 '15 at 11:46
  • @AlanMachado No, I'm using Hetzner and their "KonsoleH" only errors there are 404s for robots.txt and a poorly linked favicon.ico from one of the other pages. – Jim Oct 21 '15 at 11:52
  • 1
    Oh look! "Display errors" in the "PHP config" was disabled *facepalm* I've enabled it now and i'm getting: `Parse error: syntax error, unexpected 'if' (T_IF), expecting ',' or ';' on line 359` No surprises there. line 359 is: `if (isset($_POST['locationName'])) {` – Jim Oct 21 '15 at 11:55
  • So... we have a winner(?) :D – al'ein Oct 21 '15 at 12:17
  • Well, uhm, we do? I've been googling that error and still haven't found a solution to why it's breaking @AlanMachado... – Jim Oct 21 '15 at 12:50
  • Oh wow, OK, that was very blind of me. I've JUST realised what that error message meant. *feeling a little sheepish now* I was missing the ending `;` on the previous line. I was totally distracted by the error telling me that the error was on line 359. Thanks for helping me guys! – Jim Oct 21 '15 at 13:06

1 Answers1

-2
<input type="checkbox" name="lead" value="1" <?php if(isset($_POST['lead'])){echo "checked='checked'";} ?> />Lead Required<br>

try to use braces and check

Domain
  • 10,694
  • 2
  • 19
  • 41