5 Replies - 3091 Views - Last Post: 06 April 2011 - 05:18 AM Rate Topic: -----

#1 cowcow8866  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-April 11

Problem of embedding php code after html tag <div>

Posted 05 April 2011 - 09:44 AM

When I execute this code in AppServ, the code
 $sql1 = "SELECT M.login_name, M.nickname, M.sex, N.money, N.rank, N.rank_point FROM userbasicinfo M, usergameinfo N WHERE M.login_name = \"$username\" AND M.user_id = N.user_id;";

		 $check_user_info = mysql_query($sql1);
while(list($login_name, $nickname, $sex, $money, $rank, $rank_point)=mysql_fetch_row($check_user_info)){
	echo $login_name;
	echo $nickname;
	echo $sex;
} 

just display it as text. i.e. I receive 「END; = "SELECT M.login_name, M.nickname, M.sex, N.money, N.rank, N.rank_point FROM userbasicinfo M, usergameinfo N WHERE M.login_name = \"cowcow\" AND M.user_id = N.user_id;"; = mysql_query(); while(list(, , , , , )=mysql_fetch_row()){ echo ; echo ; echo ; } echo<<」 as result.
I am not sure whether I can embed php code after <div> tag. As I embed in other places, I can get the normal result. Unfortunately, I must put the above code in that place. So any solution to that? Thank you. I have tried to pass the result to xml and use xls to format it, it fails again.

<?php
$check = 0;
require("connect.php");
$username = $_POST['username'];
$password = $_POST['password'];
$link = mysql_connect("localhost", "root", "5566");
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$check1 = mysql_select_db("wota");
$sql = "SELECT login_name, password FROM userbasicinfo;";


$check = mysql_query($sql);

$row = mysql_num_rows($check);

$db_user_name[$row];
$db_password[$row];
$i=0;
while(list($name, $password1)=mysql_fetch_row($check)){

	$db_user_name[$i] = $name;
	$db_password[$i] = $password1;
	$i++;
}
$i=0;
while ($i<$row){
//echo $db_user_name[$i];
//echo $db_password[$i];
if($db_user_name[$i] ==$username && $db_password[$i] == $password){
//echo "Yes";
$check = 1;
//echo $check;
}
$i++;
}

if($check!=1){

echo "NO";
echo<<<END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>WoWZa - A World of Warcraft template by Mub @ Clantemplates.com</title>

<script type="text/javascript"> 
<!-- 
function ctRoster(usrName, usrLevel) 
{ 
	var collection = "Player Name: <strong>" +usrName+ "</strong> | Level: <strong>" +usrLevel+ "</strong>"; 
	document.getElementById('rosterdata').innerHTML = collection; 
} 
function ctRosterClean() 
{ 
	document.getElementById('rosterdata').innerHTML = "Rollover an image above for info."; 
} 
// --> </script>

<style type="text/css">
<!--
@import url("style.css");

-->
</style>
</head>

<body>

<div id="wrap">
  <p align="center"><img src="i/profile.png"></p>
  <div class="main">
				<ul>
					<center><li><a href="index.html"> Home</a></li>
					
					<li><a href="/forums"> Forums</a></li>
					<li><a href="links.html"> Links </a></li>
					<li><a href="downloads.html">Downloads</a></li>
					<li><a href="news.html">News</a></li>
					<li><a href="tutorial.html">Tutorial</a></li></center>
					
				</ul>
			</div>
  <div id="content">
		<div id="left">
		
	
			<div class="side-bg">
			
			
		-
			</div>
			?
			
		  <div class="side-bg" style="padding:10px 5px 0 15px; width:205px;">			
			<!-- Edit ('Ghandi', '60') etc. to show name and level -->
			
			
			</div>
			<div style="text-align:center; margin-top:10px;">
	
		     
		      <p>For the requirement of each level, please click here. </p>
			</div>
			


		</div>
		<div id="right">
		<!--	<h1>Login</h1>-->
			
		
	<!--	<h1>My Friend's list</h1>-->
	<!--PHP will be used to generate this part -->
	
		<div class="side-bg">
	<center></center></div>
		</div>
		<!-- PHP will be used to generate this part-->
		<div id="middle">
                  Login failed 
<p align = "center"><a href = "index.html"> Pleease cliok here to return back.</a> </p>			  
	</div>

		<p>&nbsp;</p>
  </div>
			<div style="color:#371603; line-height:1px; font-size:1px; height:1px; overflow:hidden;">Mubz0r_R0ckz0r</div>

</div>
</body>
</html>
END;
}
 else{




 //echo "YES, you are right";

echo<<<END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>WoWZa - A World of Warcraft template by Mub @ Clantemplates.com</title>

<script type="text/javascript"> 
<!-- 
function ctRoster(usrName, usrLevel) 
{ 
	var collection = "Player Name: <strong>" +usrName+ "</strong> | Level: <strong>" +usrLevel+ "</strong>"; 
	document.getElementById('rosterdata').innerHTML = collection; 
} 
function ctRosterClean() 
{ 
	document.getElementById('rosterdata').innerHTML = "Rollover an image above for info."; 
} 
// --> </script>

<style type="text/css">
<!--
@import url("style.css");

-->
</style>
</head>

<body>

<div id="wrap">
  <p align="center"><img src="i/profile.png"></p>
  <div class="main">
				<ul>
					<center><li><a href="index.html"> Home</a></li>
					
					<li><a href="/forums"> Forums</a></li>
					<li><a href="links.html"> Links </a></li>
					<li><a href="downloads.html">Downloads</a></li>
					<li><a href="news.html">News</a></li>
					<li><a href="tutorial.html">Tutorial</a></li></center>
					echo <<<END
					echo "DIU NEI":
					END;
				</ul>
			</div>
  <div id="content">
		<div id="left">
		
			<h1>Profile</h1>
			<div class="side-bg">
			
			  <img src="i/profile.gif" />
		    <P class="add">Please change your profile picture here.            		                
			<form id="form1" enctype="multipart/form-data" method="post" action="">
			  
			    <P class="add">File:
			      <input type="file" name="file" />
	          	<input type ="submit" name ="submit" value="go" />
			</form>
			</div>
			
		<!--style="padding:10px 5px 0 15px; width:205px;"-->
		  <div class="side-bg" >
 
			<!-- Edit ('Ghandi', '60') etc. to show name and level -->
					
			
				<div id="rosterdata">   </div>
			
				?
			
			  
				
			</div>
			
			<div style="text-align:center; margin-top:0px;">
			<h1>Fighting History </h1>		 
   55454546546546546
		    
		      
			</div>
								


		</div>
		<div id="right">
		<!--	<h1>Login</h1>-->
			
		
	<!--	<h1>My Friend's list</h1>-->
	<!--PHP will be used to generate this part -->
		<h1>My Friend's list</h1>
		<div class="side-bg">
	<center>User name: Test1</center></div>
		</div>
		<!-- PHP will be used to generate this part-->

		<div id="middle">
	END;
		 $sql1 = "SELECT M.login_name, M.nickname, M.sex, N.money, N.rank, N.rank_point FROM userbasicinfo M, usergameinfo N WHERE M.login_name = \"$username\" AND M.user_id = N.user_id;";

		 $check_user_info = mysql_query($sql1);
while(list($login_name, $nickname, $sex, $money, $rank, $rank_point)=mysql_fetch_row($check_user_info)){
	echo $login_name;
	echo $nickname;
	echo $sex;
} 
		echo<<<END
		
	</div>

		<p>&nbsp;</p>
  </div>
			<div style="color:#371603; line-height:1px; font-size:1px; height:1px; overflow:hidden;">Mubz0r_R0ckz0r</div>

</div>
</body>
</html>
END;
mysql_close($link);
}
?>



Is This A Good Question/Topic? 0
  • +

Replies To: Problem of embedding php code after html tag <div>

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

Re: Problem of embedding php code after html tag <div>

Posted 05 April 2011 - 10:05 AM

It looks to me like you're mixing PHP, HTML, and Javascript. That's an excellent way to confuse yourself!

Start by understanding that they're different languages that aren't even processed at the same time or on the same computer. Then, learn to separate them:
http://www.dreaminco...ode-separation/
Was This Post Helpful? 0
  • +
  • -

#3 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: Problem of embedding php code after html tag <div>

Posted 05 April 2011 - 10:07 AM

Your PHP code should be always enclosed within php tags like this:
<?php 

//Your code

?>


If you have HTML code after PHP code and again PHP, then you must reopen the tag and close it.
<?php

//code
?>

<br/>
<!-- HTML CODE -->

<?php
// more php code
?>

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3393
  • View blog
  • Posts: 9,591
  • Joined: 08-June 10

Re: Problem of embedding php code after html tag <div>

Posted 05 April 2011 - 12:28 PM

seems like your Heredoc syntax gets messed up somewhere. I’d put a space between echo and <<<END first to see if that's the reason.

Edit: line #243, remove the spaces before END; that’s invalid.

This post has been edited by Dormilich: 05 April 2011 - 12:30 PM

Was This Post Helpful? 0
  • +
  • -

#5 cowcow8866  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-April 11

Re: Problem of embedding php code after html tag <div>

Posted 06 April 2011 - 04:41 AM

View PostDormilich, on 05 April 2011 - 12:28 PM, said:

seems like your Heredoc syntax gets messed up somewhere. Id put a space between echo and <<<END first to see if that's the reason.

Edit: line #243, remove the spaces before END; thats invalid.

Thanks. The bug is really caused by having spaces in front of "END;".

Besides using heredoc syntax, I would also like to ask what other methods I can use to output a string with multiple lines and lots of escape characters?
Was This Post Helpful? 0
  • +
  • -

#6 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 943
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: Problem of embedding php code after html tag <div>

Posted 06 April 2011 - 05:18 AM

View Postcowcow8866, on 06 April 2011 - 07:41 AM, said:

View PostDormilich, on 05 April 2011 - 12:28 PM, said:

seems like your Heredoc syntax gets messed up somewhere. I’d put a space between echo and <<<END first to see if that's the reason.

Edit: line #243, remove the spaces before END; that’s invalid.

Thanks. The bug is really caused by having spaces in front of "END;".

Besides using heredoc syntax, I would also like to ask what other methods I can use to output a string with multiple lines and lots of escape characters?


One way I like to do it especially for HTML syntax is to put the HTML in a file by itself and places where I want to replace data I place markers there. Then I replace the markers with my desired text.

Example
<!-- HTML FILE -->
<html>
  <head>
     <title>{title}</title>
  </head>
  <body>
     {body}
  </body>
</html>


<?php
#PHP FILE
#You could say a small template system
#You can even use ob_start() and ob_end_flush();
$html = file_get_contents("htmlfile.html");
$html = str_replace("{title}", "HTML FILE!!!", $html);
...
echo $html;
?>


This post has been edited by Dormilich: 06 April 2011 - 07:23 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1