Parse error: syntax error, unexpected '<'
I'm new to this PHP and MySQL world. I've been given an assignment about simple system. But i got this error and i don't know how to fix it. Hope you guys can help me.
<?php
include ("config.php");
mysql_select_db("dbpelanggan") or die(mysql_error());
echo "Sambungan ke pangkalan data berjaya!";
$result = mysql_query("SELECT * FROM pelanggan") or die(mysql_error());
while($row = mysql_fetch_array( $result ))
{ <table width="70%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<th>ID Pelanggan</th>
<th>Nama Pelanggan</th>
<th>Kod Pelanggan</th>
</tr>
<tr>
echo ".$row['idPel'].;
echo ".$row['NamaPelanggan'].;
echo ".$row['KodPelanggan'].;
</tr>
</table>
}
?>
and the error is
Parse error: syntax error, unexpected '<' in C:xampp2htdocsLIAssignment1proses_simpan2.php on line 10
thanks in advance.
You have errors in your code.. many errors. The following code works
<?php
include ("config.php");
mysql_select_db("dbpelanggan") or die(mysql_error());
echo "Sambungan ke pangkalan data berjaya!";
$result = mysql_query("SELECT * FROM pelanggan") or die(mysql_error());
echo '<table width="70%" border="1" cellspacing="0" cellpadding="0" align="center">'
. ' <tr>
<th>ID Pelanggan</th>
<th>Nama Pelanggan</th>
<th>Kod Pelanggan</th>
</tr>';
while($row = mysql_fetch_array( $result )){
echo"<tr>
<td>".$row['idPel']."</td>
<td>".$row['NamaPelanggan']."</td>
<td>".$row['KodPelanggan'].
"</td></tr>";
}
echo "</table>";
?>
try this :
HTML
code cannot call together with PHP
code. You need to open and close PHP
every time before you try to start your HTML
code and open your PHP
code after HTML
code every time before you try to start PHP
code after HTML
.
<?php
include ("config.php");
mysql_select_db("dbpelanggan") or die(mysql_error());
echo "Sambungan ke pangkalan data berjaya!";
$result = mysql_query("SELECT * FROM pelanggan") or die(mysql_error());
while($row = mysql_fetch_array( $result ))
{
?> //you need to close php here
<table width="70%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<th>ID Pelanggan</th>
<th>Nama Pelanggan</th>
<th>Kod Pelanggan</th>
</tr>
<tr>
<?php // open php here
echo $row['idPel'].$row['NamaPelanggan'].$row['KodPelanggan'].;
?> //close php here
</tr>
</table>
<?php //open php here
}
?>
You need to open and close the php when you want to have some HTML code. So in your case you will have something like this:
<?php
include ("config.php");
mysql_select_db("dbpelanggan") or die(mysql_error());
echo "Sambungan ke pangkalan data berjaya!";
$result = mysql_query("SELECT * FROM pelanggan") or die(mysql_error());
while($row = mysql_fetch_array( $result )) { ?>
<table width="70%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<th>ID Pelanggan</th>
<th>Nama Pelanggan</th>
<th>Kod Pelanggan</th>
</tr>
<tr>
<?php echo $row['idPel']; ?>
<?php echo $row['NamaPelanggan']; ?>
<?php echo $row['KodPelanggan']; ?>
</tr>
</table>
<?php
}
?>
链接地址: http://www.djcxy.com/p/69462.html
上一篇: 解析错误:语法错误,意外的T
下一篇: 解析错误:语法错误,意外的'<'