Tom
Tom

Reputation: 1

PHP retrieve output from MySQL

echo "<td>" . "<input type=text name=name value=". $inventory['part_name']. " </td>";

When I print this, it only shows "air". However, what is stored inside the database is "air filter". What is the problem? It only prints until before the space. Is there any other way to show the text include after the space text? The above code is inside the PHP.

Upvotes: 0

Views: 34

Answers (3)

Hamza Zafeer
Hamza Zafeer

Reputation: 2446

The Best Way is that always separate HTML and PHP so that easily readable. you can do in following format. In this format error are reduce.

<td>
   <input type='text' name='name' value='<?php echo $inventory['part_name']; ?>'>
</td>

Upvotes: 0

Ravi Hirani
Ravi Hirani

Reputation: 6539

As described by jszobody's answer, you have missed quotes and > before </td> tag.

Simply write:-

echo "<td><input type='text' name='name' value='{$inventory['part_name']}'></td>";

Hope it will help you :-)

Upvotes: 0

jszobody
jszobody

Reputation: 28959

You're missing quotes around the html attributes, and the closing angle bracket for your input element.

Try this:

echo "<td><input type='text' name='name' value='". $inventory['part_name']. "'></td>";

Note this assumes you won't have a single quote in your $inventory['part_name'], might be good to escape that.

Upvotes: 2

Related Questions