I am using the mysql_fetch_row to obtain the results from a select query to a Mysql database and populate the text fields of a given form using the values generated. The values are retrieved perfectly by the select but the following problem occurs when the values popluate the text fields
eg if if I have an entry "web programmer" in the table, the text field is only polpulated by the first word before the space that is "web" and programmer disappears.
So basically everything after the space is being truncated on dispaly in the text box.
Kindly let me know what the error could be.
Thanks
Sulen
mysql_fetch_row problem
Moderator: General Moderators
the code for mysql_fetch_row problem
This is the code that I am using to perform the required functions spoken about.
mysql_select_db("altura");
$sql = "select * from directory where pno like '%".$pno."%'";
$result = mysql_query($sql);
//$num_results = mysql_num_rows($result);
//for($i=0; $i <$num_results; $i++)
while($i = mysql_fetch_row($result))
{
echo $i[3];?>
<form action='uconfirm.php' method='post'>
<p>Update Employee Information</p>
<p> Last Name
<input type=text size=40 name=lname value=<?=$i[0]?>>
<br><BR>
First Name
<input type=text size=40 name=fname value=<?=$i[1]?>>
<br><BR>
Branch
<input type=text size=40 name=region value=<?=$i[2]?>>
<br><BR>
Title
<input type=text size=40 value=<?=$i[3]?>>
<br><BR>
<input type=submit value=Update></p></form></body>
</html>
<?
}
?>
mysql_select_db("altura");
$sql = "select * from directory where pno like '%".$pno."%'";
$result = mysql_query($sql);
//$num_results = mysql_num_rows($result);
//for($i=0; $i <$num_results; $i++)
while($i = mysql_fetch_row($result))
{
echo $i[3];?>
<form action='uconfirm.php' method='post'>
<p>Update Employee Information</p>
<p> Last Name
<input type=text size=40 name=lname value=<?=$i[0]?>>
<br><BR>
First Name
<input type=text size=40 name=fname value=<?=$i[1]?>>
<br><BR>
Branch
<input type=text size=40 name=region value=<?=$i[2]?>>
<br><BR>
Title
<input type=text size=40 value=<?=$i[3]?>>
<br><BR>
<input type=submit value=Update></p></form></body>
</html>
<?
}
?>
- trollll
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 10, 2003 11:56 pm
- Location: Round Rock, TX
- Contact:
You need to enclose the html attribute in quotes. If you don't, it will think that the next word in the attribute value actually counts as the next attribute.
Ex.
You may want to check out w3school's xhtml section for some good coding practices. Even if you just apply some principles to your html it should help a bit.
Ex.
Code: Select all
<input type="text" size="40" name="title" value="Two Words" />
rather than
<input type=text size=40 name=title value=Two Words />