Click to See Complete Forum and Search --> : How to use php inside the html tags


bang_iti08
08-12-2008, 12:47 AM
hai all, now i want to display fetched datas in my html design pages.
for ex:
i display db data for name "hai" to approperiate text box in html codes.
im using this format:
<input type="text" value="<?echo $name?>"> but it will display <?echo $name?> . how to use php inside the html codes help for me!...

scragar
08-12-2008, 12:50 AM
I think you need to leave a space after the ?

anyway, this should work just as well, and it's much shorter:
<input type="text" value="<?=$name;?>">

I'd also check you have PHP configured to run right, unless you already know that it is.

NogDog
08-12-2008, 01:06 AM
I would recommend using the full "<?php" or "<?php echo" instead of the short tags ("<?" or "<?="), as the long version is guaranteed to always work, while the short versions require that the short_open_tag option be turned on, possibly making portability problems for your code if you use the short versions.

bang_iti08
08-14-2008, 12:05 AM
hi scragr, yr told this code would be work.
php code:
<input type="text" value="<?=$name;?>"> im tiring this codes. but it will not work. it will shows same values.i need another ways.. i will paste my full codes
php with html codes:
<html>
<HEAD>
<TITLE>DISPLAY</TITLE>
</HEAD>
<BODY bgcolor="#FACBDA">
<FORM name="form" method="post">
<CENTER><input type="hidden" name="id" value="<? =$id; ?>">
<H1><FONT face="times new roman" color="Green">WELCOME TO LOGIN PAGE</FONT></H1>
<TABLE border="2" cellpadding='1' cellspacing='1'>
<?php

$con=mysql_connect("localhost","root","");
mysql_select_db("mohamed",$con);
$result= mysql_query("SELECT * FROM abu");
while($row = mysql_fetch_array($result))
{
$id = $row["S_NO"];
$user = $row["USER_NAME"];
$pass = $row["PASS_WORD"];
echo $id;echo $user;echo $pass;
}
?>
<TR><TD>
S.NO:</TD><TD><INPUT type="text" name ="<?$id;?>" size="7" value="<? =$id;?>"></TD></TR>
<TR><TD>
USER NAME:</TD><TD><INPUT type="text" name="user" size="15" value="<? =$user;?>"></TD></TR>
<TR><TD>PASSWORD:</TD><TD><INPUT type="text" name="pass" size="15" value="<? =$pass;?>"></TD></TR>
<TR><TD colspan="2"><a href="display.php?id="<?=$id-1;?>">Pervious</a>&nbsp;&nbsp;
<INPUT type="button" value="Close" onclick="window.close()">&nbsp;&nbsp;<a href="display.php?id="<? =$id+1;?>">Next</a></TD></TR>
</TABLE></CENTER></FORM>
</BODY>
</HTML>

Sheldon
08-14-2008, 01:36 AM
You have spaces !
// Bad
<? =$id;?>


// Good
<?php echo($id); ?>

bathurst_guy
08-14-2008, 04:43 AM
File saved as .php? or server set to parse .htm?

maveruk
08-14-2008, 08:54 AM
File saved as .php? or server set to parse .htm?

I was about to suggest that...

bang_iti08
08-15-2008, 11:14 PM
it will finally work. very very thanks sheldon. see u....