954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Display data on a textbox in PHP

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 "Reg.No.:";

Persi
Newbie Poster
17 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

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

Aser Gado
Junior Poster in Training
52 posts since Feb 2011
Reputation Points: 10
Solved Threads: 1
 

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?

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

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

vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 

Hello,
please check below code:

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

echo "Reg.No.:";
?>

amitengg
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 1
 

substr function in PHP and space please !

kimhanu
Newbie Poster
10 posts since Mar 2008
Reputation Points: 7
Solved Threads: 1
 

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' />
pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
How does the text look like in the database? Five Star? or Five_Star?


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

Persi
Newbie Poster
17 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 
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?
>
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

Persi
Newbie Poster
17 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

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

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

You haven't added the quotes yet:

<input type="text" name="name" value="<?php echo $name; ?>"><br/>
pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

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.

Persi
Newbie Poster
17 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

Show your new code then.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

You haven't added the quotes yet:

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

Student Name:"

Persi
Newbie Poster
17 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 
$name = end(explode(" ", $row['name']));  // Star
$name = explode(" ", $row['name']));  // Five
Sorcher
Junior Poster
191 posts since Oct 2010
Reputation Points: 16
Solved Threads: 9
 

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/>";
diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

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

Karthik_pranas
Posting Pro
564 posts since Feb 2011
Reputation Points: 96
Solved Threads: 97
 
Post full code or a block of your code that contains the above line.

echo "Student Name:";

Persi
Newbie Poster
17 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

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

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
echo "Student Name:";

Thank u so much everyone. I got the solution.

Persi
Newbie Poster
17 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: