My database field contains a sentence as a varchar suppose “Hello I am online” I want to show that field as a input placeholder. I write the following code but it shows only “Hello”. but if I place echo command then if shows the full sentence. I think i am making some silly mistakes but could not find what is that. please help.
JavaScript
x
<?php
$servername = "localhost:3306";
$username = "admin";
$password = "pass";
$dbname = "test_db";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Database Connection failed: " . $conn->connect_error);
}
$sql = "select * from test_table";
$sqldata = $conn->query($sql);
if(! $sqldata)
{
die ("error opening database");
}
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<div class="form_layout">
<?php while( $row = $sqldata->fetch_assoc()) : ?>
<div >
<label> Name :</label>
<input type="text" id="iname" name="institutename" placeholder=<?php echo $row['msg']; ?>>
<?php echo $row['msg']; ?>
</div>
<?php endwhile ?>
</div>
</form>
it showing “hello” in the input section but”Hello I am online” on the next echo command.
Advertisement
Answer
Your mistakes is here
JavaScript
placeholder=<?php echo $row['msg']; ?>
Replace this
JavaScript
placeholder="<?php echo $row['msg']; ?>"