Page 1 of 1

Embed php code in HTML

Posted: Tue Apr 10, 2012 8:27 am
by cliff
Hi!

I am new to PHP. I am trying to store array values in HTML table. For that I have written following code. Everything worked before I embedded php code. After I added php code I got an error HTTP 500 Internal Server error. Please help me.

Below is the code:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>
Please select your desired states:
<br><br>
<?php
$state_list = array("AL"=>"Alabama","AK"=>Alaska");
?> 
<form id=form1 >
	<table id=myTable border=1>
		<tr>
			<th>Column 1</th>
			<th>Column 2</th>
			<th>Column 3</th>
		</tr>
<?php foreach ($state_list as $row) { ?>
	<tr>
       <td><?php echo $row[0]; ?></td>
       <td ><?php echo $row[1]; ?></td>
       <td ><?php echo $row[2]; ?></td>
</tr>
     <?php } ?>

		
</table>
	<br>
	<input type='submit' value='Save' onclick=" " />
</form>
</body>
 </head>
</html>


thanks for the help in advance

Re: Embed php code in HTML

Posted: Tue Apr 10, 2012 8:48 am
by social_experiment

Code: Select all

<?php
// missing a " infront of Alaska
$state_list = array("AL"=>"Alabama","AK"=>Alaska");
?>
There is a missing " in the syntax above, not sure if that is what is causing the issue

Re: Embed php code in HTML

Posted: Tue Apr 10, 2012 9:22 am
by cliff
Hi, Thanks for the help. Exactly, That is what caused the error. Thanks again.

Now, I am trying to click/select the data of table cell. To achieve this, I am trying jQuery code. Is there any easier way to achieve this than using jQuery. Your direction would be helpful. Thanks.

Re: Embed php code in HTML

Posted: Tue Apr 10, 2012 4:53 pm
by social_experiment
You could use javascript but jQuery should be fine; have a look at this url for more help on the subject http://coderzone.org/library/Get-Table- ... k_1014.htm

Re: Embed php code in HTML

Posted: Wed Apr 11, 2012 10:15 am
by danjapro
Simply converting your page to extension .phtml, will allow you to utilize php code structure without editing or adding any jQuery.