php+html on DW doesn't execute

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
NICORI
Forum Newbie
Posts: 1
Joined: Sat Feb 12, 2011 9:34 am

php+html on DW doesn't execute

Post by NICORI »

Hi
can anyone please tell me how come the following code doesn't work? I have tested it with the php only and it went ok, there was a connection to the database.
somehow with the combination to the html the php code appears to be in a box that says php.

I changed the password for this display ofcourse!







<?php
$db=mysql_connect("localhost","root","password");
if(!$db)
{
die("database connection failed: " . mysql_error());
}
$db_select = mysql_select_db ("widget_ori", $db);
if (!$db_select)
{
die("database selection failed: " . mysql_error());
}

?>
<html>
<head>
<title>Widget Corp</title>
<link href="stylesheets/public.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<h1>Widget Corp</h1>
</div>
<div id="main">

<table id="structure">
<tr>
<td id="navigation"><?php
$result= mysql_query ("SELECT * FROM subjects", $db);
if (!$result)
{
die("database selection failed: " . mysql_error());
}
while ($row = mysql_fetch_array($result))
{

echo $row["menu_name"]." ".$row["position"]. "<br />";
}
?>
</td>
<td id="page">
<h2>Content Area</h2>
<p>Welcome to the staff area.</p>
<ul>
<li><a href="content.php">Manage Website Content</a></li>
<li><a href="new_user.php">Add Staff User</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</td>
</tr>
</table>
</div>
<div id="footer"> Copyright widget ori 2011 </div>
</body>
</html>
<?php
mysql_close($db);


?> :( :(
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Re: php+html on DW doesn't execute

Post by litebearer »

Just some bleary-eyed changes...
(BTW: please use the 'PHPCode' tags when posting code) :D

Code: Select all

<?php
$db=mysql_connect("localhost","root","password")or die("database connection failed: " . mysql_error());
$db_select = mysql_select_db("widget_ori", $db) or die("database selection failed: " . mysql_error());
?>
<html>
<head>
<title>Widget Corp</title>
<link href="stylesheets/public.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>

<div id="header">
	<h1>Widget Corp</h1>
</div>

<div id="main">
	<table id="structure">
		<tr>
			<td id="navigation">
				<?php
				$result= mysql_query ("SELECT * FROM subjects", $db) or die("database selection failed: " . mysql_error();
				while ($row = mysql_fetch_array($result)){
					echo $row['menu_name']." ".$row['position']. "<br/>";
				}
				?>
			</td>
			<td id="page">
				<h2>Content Area</h2>
				<p>Welcome to the staff area.</p>
				<ul>
					<li><a href="content.php">Manage Website Content</a></li>
					<li><a href="new_user.php">Add Staff User</a></li>
					<li><a href="logout.php">Logout</a></li>
				</ul>
			</td>
		</tr>
	</table>
</div>

<div id="footer"> Copyright widget ori 2011 </div>
</body>
</html>
<?php
mysql_close($db);
?>
Post Reply