error while moving from php to html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

error while moving from php to html

Post by rami »

i have just made a page which works with code

Code: Select all

<?
session_start();
//require_once ('includes/config.inc'); 
require_once ('../mysql_connect1.php'); 
$page_title = 'view';

if (!isset($_SESSION['name'])) {	
header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/login.php");	ob_end_clean(); 
	exit(); 	
} else
{

	if (isset($_GET['uid'])) 
	{
			$query = "SELECT * FROM students WHERE user_id =". $_GET['uid']."";
			$result= mysql_query($query);

		if (mysql_num_rows($result) > 0) 
		{ // if there are any rows of data, fetch the data			
				$row = mysql_fetch_array ($result);
				echo '<p>Name: ' . $row['name'] . '<br />';
				echo '<p>Email: ' . $row['email'] . '<br />';
				echo '<p>Address: ' . $row['address'] . '<br />';
		} 
		else 
		{
			echo '<p>No data returned!</p>';
		} // mysql if end
	}
	else 
	{
		echo '<p>Student not found.</p>';
}
}

/*else {
echo '<p>Missing uid!</p>';
}
*/
?>
as it was displaying text in very pain thing i tried to format it as follows....

Code: Select all

if (isset($_GET['uid'])) 
	{
	$query = "SELECT * FROM students WHERE user_id =". $_GET['uid']."";
			$result= mysql_query($query);
if (mysql_num_rows($result) > 0)
{
$row = mysql_fetch_array ($result);

<table border="1" width="100%">
  <tr>
    <td width="100%" colspan="2" bgcolor="#00659C"><font color="#FFFFFF"><b>&nbsp;Welcome
      ,</b></font></td>
  </tr>
  <tr>
    <td width="72%" rowspan="4" valign="top">
      <table border="1" width="100%" bgcolor="#EFEFEF" bordercolor="#FFFFFF">
        <tr>
          <td width="51%">echo '<p>Name: ' . $row['name'] . '<br />';</td>
          <td width="49%" rowspan="3" bordercolor="#FFFFFF">&nbsp;</td>
        </tr>
        <tr>
          <td width="51%">echo '<p>Email: ' . $row['email'] . '<br />';</td>
        </tr>
        <tr>
          <td width="51%">echo '<p>Address: ' . $row['address'] . '<br />';</td>
        </tr>
      </table>
    </td>
    <td width="28%" bgcolor="#00659C">
      <p align="center">&nbsp;<b><font color="#FFFFFF">Knowledge center</font></b></td>
  </tr>
  <tr>
    <td width="28%">&nbsp;</td>
  </tr>
  <tr>
    <td width="28%" bgcolor="#00659C">
      <p align="center">&nbsp;&nbsp; <font color="#FFFFFF"><b>Status</b></font></td>
  </tr>
  <tr>
    <td width="28%">&nbsp;</td>
  </tr>
</table>
		
		} 
		else 
		{
			echo '<p>No
but it says there is error
Parse error: parse error in c:\program files\easyphp1-8\www\html\viewhtml.php on line 23
how it is done can any body copy code and show..
thanks for help
rami
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

You can't simply merge the two languages like that, you need to either echo/print the HTML, or you need to break in to/out of PHP using the <?php and ?> tags. (That's for your second snippet)

For the first, what is on line 23? (That's a hint by the way.. take a look at line 23 :P)
Post Reply