INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Populating multiple word string into Text Box value field

Populating multiple word string into Text Box value field

(OP)
I want to bring back records from a database into an HTML form and populate all the text boxes with values from the database. This is so I can alter the text then update it. This works perfectly ok where a text box is filled with a single word e.g. a surname. If however. I try to fill the value with a multiple word string e.g. address of "125 Smith Street", only the "125" is displayed. If I print the record to the screen, outside of the form, it displays the full address correctly showing the correct record is being retrieved from the database.
Any ideas where I am going wrong.

RE: Populating multiple word string into Text Box value field

Is the text box big enough to display the whole string?
Have a look in the source code, is the whole text there?
The text should look something like this although there could bea lot more stuff in there depending where it was created.

CODE

<input type='text' name='name' value='125 Smith Street'> 

Keith
www.studiosoft.co.uk

RE: Populating multiple word string into Text Box value field

Spaces are delimiters in HTTP so you need to URL encode the string before passing anywhere.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Populating multiple word string into Text Box value field

(OP)
I bring back the address from the database and assign it to a variable before I echo the variable in the value attribute.

$street = $row['Street']; This is from the database which is "125 Smith Street"
echo "Street = " . $street. "\n"; //I did this to see what was coming back from the database and it is okay.
This is the line in the form
<tr><td>Address - Street:</td><td><input type="text" name="street" maxlength="40" value=<? echo $street ?> ></td></tr>
Only the "125" is displayed.
I have tried just typing "$street = "125 Smith Street" but this doesn't work either. If I type that "125 Smith Street" directly into the value attribute it does display it.

The whole code in PHP
is

CODE --> PHP

<?php
	session_start();
	
	if (isset($_SESSION['playNo']))
		{
		$playerNo = $_SESSION['playNo'];
		unset($_SESSION['playNo']);
	}else{
		$playerNo = ($_GET['playerId']);
		echo "PlayerId = " . $playerNo. "\n";
	}
	
	
	$query = "SELECT PlayerNo, FirstName, Surname, PreferredName, Dob, Street, 
				TownSuburb, State, Postcode, Handicap, StateRep, Status FROM Player WHERE PlayerNo =  ". $playerNo ;
	$mysqli = mysqli_connect("localhost", "User", "password", "2015GolfChamps");
	if (mysqli_connect_errno($mysqli)) {
    	echo "Failed to connect to MySQL: " . mysqli_connect_error();
	}
	$res = mysqli_query($mysqli, $query);
	
	$row = mysqli_fetch_assoc($res);
	$street = $row['Street'];
	$name = $row['Surname'];
	echo "Street = " . $street. "\n";
	 
?>
<html>

<head><title>Person Record</title></head>
<h2><center>Player Details</center></h2>
<br /><br /><br /><br />
<body>
<form action="addPlayer.php" method="POST">
<center><table vertical-align: top>
	
	<tr><td><input type="hidden" name="playerNo" value=<?php echo $row['PlayerNo'] ?> ></td></tr>
	<tr><td>Surname:</td><td><input type="text" name="surname" value=<?php echo $name ?> ></td></tr>
    <tr><td>First Name:</td><td><input type="text" name="firstName" value=<?php echo $row['FirstName'] ?> ></td></tr>
    <tr><td>Preferred Name:</td><td><input type="text" name="preferredName" value=<?php echo $row['PreferredName'] ?> ></td></tr>
    <tr><td>Date of Birth:</td><td><input type="text" name="preferredName" value=<?php echo $row['Dob'] ?> ></td></tr>
	<tr><td>Address - Street:</td><td><input type="text" name="street" maxlength="40" value=<? echo $street ?> ></td></tr>
	<tr><td>Town/Suburb:</td><td><input type="text" name="suburb" value=<?php echo $row['TownSuburb'] ?> ></td></tr>
	<tr><td>State:</td><td><input type="text" name="state" value=<?php echo $row['State'] ?> ></td></tr>
	<tr><td>Postcode:</td><td><input type="text" name="postcode" value=<?php echo $row['Postcode'] ?> ></td></tr>
    <tr><td>Handicap:</td><td><input type="text" name="handicap" value=<?php echo $row['Handicap'] ?> ></td></tr>
 	<tr><td>State playing for:</td><td><input type="text" name="stateRep" value=<?php echo $row['StateRep'] ?> ></td></tr>
 	<tr><td>Status:</td><td><input type="text" name="status" value=<?php echo $row['Status'] ?> ></td></tr>
 	<tr><td> </td></tr>
 	<tr><td> </td></tr>

</table></center>
<center><input type="submit" value="Update record"/></center>
</form>	
	
<center><a href="index.html">Cancel</a></center>
</body>
</html> 

RE: Populating multiple word string into Text Box value field

What does the code look like AFTER it has been delivered to a browser?


And this:

value=<? echo $street ?> >

Should be value="<? echo $street ?>" >

Otherwise the space will be used as a delimiter for the value.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Populating multiple word string into Text Box value field

Chris is right. Spaces are delimiters for values in HTML. If you don't quote the value you output the browser ends it at the first space, and takes the rest of the string as other properties of the html element.

CODE

<input type="text" name="street" maxlength="40" value="<? echo $street ?>" 

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: Populating multiple word string into Text Box value field

(OP)
That's it. Thank you very much. It's okay now.
John

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close