Is This PHP Within HTML?

Hello,

I found and used a script that works, but I don’t understand how it echos PHP within HTML. Please look at the following:

[php]echo "


<input type=‘hidden’ name=‘id[$i]’ value=’{$row[‘id’]}’ />
{$row[‘id’]}

<input class=‘scroller_field’ type=‘text’ size=‘20’ name=‘date[$i]’ value=’{$row[‘date’]}’ />
<input class=‘scroller_field’ type=‘text’ size=‘20’ name=‘location[$i]’ value=’{$row[‘location’]}’ />
<input class=‘scroller_field’ type=‘text’ size=‘42’ name=‘event[$i]’ value=’{$row[‘event’]}’ /> ";[/php]

‘echo’ is started with a double quote with single quotes used as HTML code. It’s as if the variables for name and value are being read by HTML, not PHP. Am I misunderstanding something here?

Not sure if I understand the problem. What does the HTML source look like when you run it?

If you are using a .html extension your server must be configured to parse PHP using that extension.

PHP is echoing the HTML code with PHP variables in it. $i and $row are both PHP variables that should have double quotes around them, not single quotes?

I’m still not sure what you are saying. The syntax of this code is fine.

Ok… I looked at the page’s source code. The use of [] is throwing me off. Where it has id[$i] it looks like id is a part of PHP, and I didn’t know you can write HTML as id[3] or something like that.

I still don’t understand {$row[‘id’]}. Why do you need the {} around it there and not in id[$i]? Is there a PHP page that explains this?

Using [] in a form is a way to send arrays. It would be similar to having a URL like ?var[]=1&var[]=2&var[]=3 which would give you an array of var = array(1, 2, 3)

Check this page for info about the curly brackets. See the section about variable parsing (simple vs complex)

http://php.net/manual/en/language.types.string.php

Ok, thank you, Matt. I’ll read over that information.

Sponsor our Newsletter | Privacy Policy | Terms of Service