While displaying the data from the database on a text box, I can access only the first part of the name. For example, if the name is 'Five Star', only the name 'Five' is displayed. Can you help in this? I'm just a beginner.
This is the code i've used echo "<tr><td>Reg.No.:</td><td width='200'><input type='text' name='reg' value=".$row[RegNo]."></td></tr>";

Recommended Answers

All 19 Replies

How does the text look like in the database? Five Star? or Five_Star?

Member Avatar for diafol

Names need to be single words. No spaces. When you say 'name', I'm assuming you mean the name attribute. If not, what do you mean?

echo 1st the $row[RegNo] to see the value, because it could be that the $row[RegNo] only contains the "five" text

Hello,
please check below code:

<?php
$reg=$row[RegNo];

echo "<tr><td>Reg.No.:</td><td width='200'><input type='text' name='reg' value='$reg'></td></tr>";
?>

substr function in PHP and space please !

commented: Do not hijack a thread, start your own. -3

If the value attribute is used without quotes, then the space (after Five in your case) will be assumed as the separator for the next attribute.

<!-- this was your output -->
<input type='text' name='reg' value=Five Stars />

<!-- this is what it should be (as amitengg showed) -->
<input type='text' name='reg' value='Five Stars' />
commented: Ah! Now I get it. Yes, agree. +15

How does the text look like in the database? Five Star? or Five_Star?

It is Five Star. Din't use any underscore.

Names need to be single words. No spaces. When you say 'name', I'm assuming you mean the name attribute. If not, what do you mean?

Why can't I use two words? Is there any way I can do this?
<input type="text" name="name" value=<?php echo $name; ?>><br/> hear it is the php code but i can't access full name it only print the first part of the name can u help me pls? but i can access full name from $name in outside the input label

Member Avatar for diafol

Sorry I misread your first post. Your value attribute can pretty much be anything

You haven't added the quotes yet:

<input type="text" name="name" value="<?php echo $name; ?>"><br/>

If the value attribute is used without quotes, then the space (after Five in your case) will be assumed as the separator for the next attribute.

<!-- this was your output -->
<input type='text' name='reg' value=Five Stars />

<!-- this is what it should be (as amitengg showed) -->
<input type='text' name='reg' value='Five Stars' />

I've used quotes for the value attribute. But it is the same.

Show your new code then.

You haven't added the quotes yet:

<input type="text" name="name" value="<?php echo $name; ?>"><br/>

Student Name:<input type='text' name='name' value=".$row.">"

$name = end(explode(" ", $row['name']));  // Star
$name = explode(" ", $row['name']));  // Five
Member Avatar for diafol

Are you using php to output the whole html?

either

<input type="text" name="name" value="<?php echo $row['name']; ?>"><br/>

OR

echo "<input type=\"text\" name=\"name\" value=\"{$row['name']}\"><br/>";

Post full code or a block of your code that contains the above line.

Post full code or a block of your code that contains the above line.

echo "<tr><td>Student Name:</td><td width='200'><input type='text' name='name' value=".$row."></td></tr>";

You are STILL missing the quotes around the value... Look again at @ardav's code.

echo "<tr><td>Student Name:</td><td width='200'><input type='text' name='name' value=".$row."></td></tr>";

Thank u so much everyone. I got the solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.