Hi I need some help please. I am trying to display mysql data on webpage.I got this example from
PHPEasyStep but it does not work. I think the code is a few years old and not compatible with
my version of Php which is 5.4.Actually I have this problem with most tutorials and it is a shame
because it causes a lot of time consuming, I wish these tutorials were updated, would be much easier.
Anyway can somebody tell me how to correct the code below so that it does work? Thanks a lot.
This is the error I get:
Parse error: syntax error, unexpected '<' in C:\inetpub\wwwroot\select.php on line 44
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Retrieve data from database
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<?php
// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td width="10%"><? echo $rows['id']; ?></td>
<td width="30%"><? echo $rows['name']; ?></td>
<td width="30%"><? echo $rows['lastname']; ?></td>
<td width="30%"><? echo $rows['email']; ?></td>
</tr>
<?php
// close while loop
}
</table>
?>
<?php
// close MySQL connection
mysql_close();
?>