I have a bit of script that reads a text string from a database and outputs it to a form which is dynamically generated by my PHP script. This is to allow users to update their contact information if there any errors.
Problem I am having is that if there is a space or any whitespace in one of the fields in the database then the script will only output the first 'chunk' of data before it moves onto the next column. I have considered removing the whitespace as it is input but I would prefer to give my users the choice.
For example....
name field on db = 'smith a'
outputtted field on html form = 'smith'
It's as though it's truncating it as soon as it sees some whitespace.
I'm using mysql_fetch_row.
Any assistance would be appreciated.
Code below.
Code: Select all
<?
$db = mysql_connect('localhost', 'DBLOGIN', 'DBPASSWORD') or die('Could not connect.');
if(!$db)
die('no db');
if(!mysql_select_db('DBNAME',$db))
die('No database selected.');
$id = $_GET['id'];
$query = "SELECT RANK, NAME, MOBILE, EMAIL, id FROM NCO_contact WHERE ID = $id";
$dataraw = mysql_query($query);
while($data = mysql_fetch_row($dataraw)) {
echo "
<form id='editdetails' method='post' action='edit.php'>
<p>
<label>Rank</label>
</p>
<p>
<select name='rank' id='rank'>
<option value='$data[0]' selected='selected'>$data[0]</option>
<optgroup label='NCOs'>
<option value='Cpl'>Corporal</option>
<option value='Sgt'>Sergeant</option>
<option value='FS'>Flight Sergeant</option>
<option value='CWO'>CWO</option>
<optgroup label='Staff'>
<option value='CI'>CI</option>
<option value='Plt Off'>Plt Off</option>
<option value='Fg Off'>Fg Off</option>
<option value='Flt Lt'>Flt Lt</option>
</select>
</p>
<p>
<label>Surname</label>
</p>
<p>
<input type='text' name='name' id='name' value=$data[1] />
</p>
<p>
<label>Mobile Number</label>
</p>
<p>
<input type='text' name='mobile' id='mobile' value=$data[2] />
</p>
<p>
<label>MSN / Email Address</label>
</p>
<p>
<input type='text' name='email' id='email' value='$data[3]'/>
</p>
<p>
<input type='submit' name='edit' id='edit' value='Update details' />
</p>
<input type='hidden' name='id' id='id' value='$id' />
</form>
</body>
";
}
?>