Click here to Skip to main content
15,885,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Helo Coders

I'm trying to retrieve mysql data on to text fields using php, my code works out fine except its not able to retrieve all the data e.g it can only retrieve 'New' in the state text field when it is supposed to retrieve 'New York'. Here is my code.....



XML
<?php
while(isset ($_POST['Go'])){
$search_table=$_POST['nrcc'];
$query = mysql_query("SELECT * FROM students WHERE NRC='".mysql_real_escape_string($search_table)."'");
while($row=mysql_fetch_assoc($query)){
echo "<table>";
echo "<form >";
echo "<tr>";
echo "<td align='right' bgcolor='#ffffcc' border='2'>Name:</td><td>" ."<input  type=text readonly class=textbox name=pc value=" .$row['FullName'] . " </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right' bgcolor='#ffffcc' border='2'>Gender:</td><td>" ."<input type=text readonly class=textbox name=status value=" .$row['Gender'] . " </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right' bgcolor='#ffffcc' border='2'>Age Group:</td><td>" ."<input type=text class=textbox name=age value=" .$row['AgeGroup'] . " </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right' bgcolor='#ffffcc' border='2'>NRC:</td><td>" ."<input type=text name=nrc  class=textbox value=" .$row['NRC'] . " </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right' bgcolor='#ffffcc' border='2'>Organisation:</td><td>" ."<input type=text minlength=12 class=textbox name=inst value=" .$row['Organisation'] . " </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right' bgcolor='#ffffcc' border='2'>Purpose:</td><td>" ."<input type=text class=textbox name=purpose </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right' bgcolor='#ffffcc' border='2'>State:</td><td>" ."<input type=text class=textbox name=state value=" .$row['Province'] . " </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right' bgcolor='#ffffcc' border='2'>Date:</td><td>" ."<input type=text class=textbox name=dbdate id=date </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='right' bgcolor='#ffffcc' border='2'>Address:</td><td>" ."<textarea  class=textbox cols=100 rows=4 name=dbdate id=date value=" .$row['Address'] . " </td> </textarea>";
echo "</tr>";
echo "<center>";
echo "<tr>";
echo "<td><input type='submit' name='save' value='Update'  /></td></tr>";
echo "</tr>";
echo "</center>";
echo "</form>";
}
echo "</table>";
}
?>
Posted
Comments
W Balboos, GHB 6-Jan-15 6:52am    
Your SELECT query? Sample data (even better: expected vs actual). Stuff like that. There's even the possibility of the sizing of the rendered columns being an issue, splitting on a word boundry for words like New York whilst displaying larger strings.
CLilium 6-Jan-15 8:27am    
Your echo "</table>"; is out of while statement, so you are making table within table within table. Also your <form> and </form> are in wrong order I think they should be both outside of <table></table> (they might be inside, but I'm not sure if it's correct way). Lastly please if you have some sense regarding web making, make all css in external file and actually use it instead of <center> for example.

If it doesn't help report back with following:
Did you check page source of the generated page for the value and did you check your data in your DB? If everything is fine, can you try to display the value just as a plain text to see whenever it's caused by <input>?

1 solution

You could try something like:

PHP
echo '<table><tbody><tr><td align="\'right\'" bgcolor="\'#ffffcc\'" border="\'2\'">State:</td></tr></tbody></table><table><tbody><tr><td>" ."<input type="text" class="textbox" name="state" value="'  .$row['Province'] . '"/></td></tr></tbody></table>


Please note the substitution of double quotes with single one (in order to wrap correctly the value attribute) and the input tag ending.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900