0

my html table is expected to display variables from mysql table using php , but the table rather displays the raw codes in its cells and not the variables

Below is the diagram of the table: table displays codes

<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="test"; // Database name 
$tbl_name="test_mysql"; // Table name 
$server_name="localhost";


// Create connection
$con = new mysqli($server_name, $username, $password, $db_name , 3306);

if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
}  

// get value of id that sent from address bar
$id=$_GET['id'];

// Retrieve data from database 
$sql="SELECT * FROM $tbl_name WHERE id='$id'";

$result = $con->query($sql);

$rows = $result->fetch_assoc();          

?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center">
<input name="name" type="text" id="name" value="<? echo $rows['name']; ?>">
</td>
<td align="center">
<input name="lastname" type="text" id="lastname" value="<? echo $rows['lastname']; ?>" size="15">
</td>
<td>
<input name="email" type="text" id="email" value="<? echo $rows['email']; ?>" size="15">
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</td>
<td align="center">
<input type="submit" name="Submit" value="Submit">
</td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?php
// close connection 
$con->close();
?>
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
faisal abdulai
  • 3,739
  • 8
  • 44
  • 66

3 Answers3

1

Try use <?php echo $rows['id']; ?>

Mohamad Arafat
  • 573
  • 1
  • 5
  • 24
1

All the php versions do not support this short cut <?= so at the server where you are executing this code you need to replace <? with <?php.

Sourabh Kumar Sharma
  • 2,864
  • 3
  • 25
  • 33
0

It seems that you are missing the php tag

If you are using a PHP version earlier than 5.4, you should use

<?php echo ... ?> 

If using PHP 5.4 or earlier, you can print by using

<?= ?>

You can find more information here: http://php.net/manual/en/language.basic-syntax.phptags.php

gusridd
  • 864
  • 10
  • 16