Getting php value in html

10k views Asked by At

I am trying to display the name retrieved from Database in html file . Referred couple of blogs, still I am not able to display the value

<?php
$result=mysql_query("SELECT * from `Data`  where Emp_Id = $EmpID")
$info = mysql_fetch_array( $result );
$Emp_ID=$info['Emp_ID'];
<html><head>
<body>
<input  name="emp_number" value=<?php echo $Emp_ID?>/>
<input name='emp_name' value="<?php echo (isset($Emp_ID) ? htmlspecialchars($Emp_ID) : ''); ?>" />
<input name='emp_name'<?php echo (isset($Emp_Name)) ? ('value = "'.$Emp_Name.'"') : "value = \"\""; ?>/>

</body></head></html>
?>

Tried three ways, but none of them worked.

3

There are 3 answers

1
raxer On BEST ANSWER

You should use a template system. Beside of that try this:

<?php
$result=mysql_query("SELECT * from `Data`  where Emp_Id = $EmpID")
$info = mysql_fetch_array( $result );
$Emp_ID=$info['Emp_ID'];
?>

<html>
<body>

<input  name="emp_number" value=<?php echo $Emp_ID; ?>/>
<input name='emp_name' value="<?php echo (isset($Emp_ID) ? htmlspecialchars($Emp_ID) : ''); ?>" />
<input name='emp_name'<?php echo (isset($Emp_ID)) ? ('value = "'.$Emp_ID.'"') : "value = \"\""; ?>/>

</body>
</html>
0
Gareth On

Looks like the Emp_ID in line three should be Emp_Id or the Emp_Id in line one should be Emp_ID.

0
Authman Apatira On

This is the third time this week I've seen a similar question to this.

  • Please search SO and look for related questions
  • $EmpID is never being set
  • Your code is vulnerable to SQL injection and your site is likely to soon get hacked
  • Your query has a discrepancy between Emp_ID and your returned result Emp_Id
  • You've got two input fields with the same name, so only one will be returned on Post/Get
  • $Emp_Name is never set anywhere (guessing it should come form info?)
  • Also on the third input, you should have a space before you echo your "value=" field