0

I am executing a php script which collects some variables from a form, then displays a page from a MySQL table. The page is displayed fine, but the echoed variable are not.

    <h4>Conference Registration</h4>
    <p><strong>
        <?php echo $confName $confDate; ?>
    </strong></p>

The expected result is that the two variable are displayed. I tested that the variable were available by inserting an echo command at the top of the page.

The actual result is that the variable are not displayed.

When displaying the page source in the browser and hovering over the <?php line displayed in red, the following is displayed:

Saw "<p". Probable cause: Attempt to use an XML processing instruction in HTML. (XML procesing instructions are not supported in HTML.)

neholtz
  • 1
  • 2
  • 2
    When viewing the source of a PHP page you should never see the actual PHP like ` – j08691 May 30 '19 at 16:26
  • I think it's more down to syntax error: `` – treyBake May 30 '19 at 16:27
  • 1
    Even a syntax error would not show ` – aynber May 30 '19 at 16:27
  • point. could @neholtz try adding `ini_set('display_errors', 1); ini_set('display_startup_errors', 1; error_reporting(-1);` at the top of your script please? – treyBake May 30 '19 at 16:28
  • @treyBake: Missing right paren on your second line. Was `ini_set('display_startup_errors', 1; Should be `ini_set('display_startup_errors', 1); No changes. php code still shows in browser source. Server is shared hosting on HM. – neholtz May 30 '19 at 17:04
  • This is for one form receiving some `$_POST variables` from the submission of another form. Before the `, but the data still does not show up on the page. – neholtz Jun 01 '19 at 19:48

3 Answers3

2

You cannot just place two variables next to each other and expect the echo command to display them. You need to use two echo commands, or place a comma between the variables:

echo $confName;
echo $confDate;

// or use comma;
echo $confName, $confDate;

Or alternatively, learn how to concatenate the variables:

echo $confName." - ".$confDate;
Mark
  • 691
  • 7
  • 20
  • my linked dupe resolves it ^^ no need to add an answer (if it turns out that's the crux of the issue) – treyBake May 30 '19 at 16:29
  • I tried the ` The php still shows up in the browser page source. – neholtz May 30 '19 at 16:52
  • So your issue is that the PHP code is physically showing in your browser? Is your page using the `.php` extension? Is your webserver configured and running properly? – Mark May 31 '19 at 09:08
2

echo takes in a string or a list of strings PHP Manual

echo can accept

  • ($confName, $confDate) (handles as a list)
  • $confName, $confDate (handles as a list)
  • $confName . $confDate (handles as a single string since it is concatenated)

so something like

<h4>Conference Registration</h4>
  <p><strong>
    <?php echo $confName, $confDate; ?>
  </strong></p>

or I would recommend using using <?=*var* ?> since it looks cleaner

As Tom Scholz mentioned, if you are on a PHP version older then 5.4.0 you must set short_open_tag=on in your php.ini file

<h4>Conference Registration</h4>
  <p><strong>
    <?=$confName.$confDate ?>
  </strong></p>
  • `=` doesn't always work, since prior to php 5.4 it was disabled by default. See https://www.php.net/manual/en/language.basic-syntax.phptags.php – Tom May 30 '19 at 16:46
  • 1
    @TomScholz Yes but that is a quick fix in the php.ini: `short_open_tag=on` for anyone on the older versions. The odds are slim from the question that he is running an older version like that. – Chris221221 May 30 '19 at 16:52
  • Just wanted to point out that it *could* be a problem :) Lots of folks are (unfortunately) still running on old php versions. – Tom May 30 '19 at 16:55
  • your first bullet will give a syntax error, the manual says explicit: "Additionally, if you want to pass more than one parameter to echo, the parameters **must not** be enclosed within parentheses." – Vickel May 30 '19 at 18:35
0

Use the concatenation operator .

<?php echo $confName.$confDate; ?>
Mohit Kumar
  • 952
  • 2
  • 7
  • 18