问题
The Query I want to get from my database is not fully showing. Its about the $straat query. All the other queries are perfectly fine.
Problem described :
This is the normal result on the main page
At Straat & Huisnummer its showing "Roelofs Mulderweg 3"
This is the problem when I try to edit it with the script
As you can see at Straat & Huisnummer the query is not fully showing anymore.
THE PHP
//selecting data associated with this particular id
$result = mysql_query("SELECT * FROM tt WHERE id=$id");
while($res = mysql_fetch_array($result))
{
$track = $res['track'];
$straat = $res['straat'];
$postcode = $res['postcode'];
$plaats = $res['plaats'];
$land = $res['land'];
$datum = $res['datum'];
$klantnummer = $res['klantnummer'];
}
?>
The HTML
<tr bgcolor='#CCCCCC'>
<td>Track & Trace</td>
<td>Straat & Huisnummer</td>
<td>Postcode</td>
<td>Plaats</td>
<td>Land</td>
<td>Datum</td>
<td>Klantnummer</td>
</tr>
<tr>
<td><input type="text" style="width:100%" name="track" value=<?php echo $track;?>></td>
<td><input type="text" style="width:100%" name="straat" value=<?php echo $straat;?>></td>
<td><input type="text" style="width:100%" name="postcode" value=<?php echo $postcode;?>></td>
<td><input type="text" style="width:100%" name="plaats" value=<?php echo $plaats;?>></td>
<td><input type="text" style="width:100%" name="land" value=<?php echo $land;?>></td>
<td><input type="text" style="width:100%" name="datum" value=<?php echo $datum;?>></td>
<td><input type="text" style="width:100%" name="klantnummer" value=<?php echo $klantnummer;?>></td>
<td><input type="hidden" name="id" value=<?php echo $_GET['id'];?>></td>
</tr>
</table>
<input type="submit" name="update" value="Update">
</form>
回答1:
As suggested in the comment:
value=<?php echo $straat;?>>
breaks due to the whitespace in the value. Replacing this line with
value="<?php echo $straat;?>">
(note the hyphens) solves the issue.
回答2:
try this:
<tr bgcolor='#CCCCCC'>
<td>Track & Trace</td>
<td>Straat & Huisnummer</td>
<td>Postcode</td>
<td>Plaats</td>
<td>Land</td>
<td>Datum</td>
<td>Klantnummer</td>
</tr>
<tr>
<td><input type="text" style="width:100%" name="track" value="<?php echo html_special_chars($track);?>"></td>
<td><input type="text" style="width:100%" name="straat" value="<?php echo html_special_chars($straat);?>"></td>
<td><input type="text" style="width:100%" name="postcode" value="<?php echo html_special_chars($postcode);?>"></td>
<td><input type="text" style="width:100%" name="plaats" value="<?php echo html_special_chars($plaats);?>"></td>
<td><input type="text" style="width:100%" name="land" value="<?php echo html_special_chars($land);?>"></td>
<td><input type="text" style="width:100%" name="datum" value="<?php echo html_special_chars($datum);?>"></td>
<td><input type="text" style="width:100%" name="klantnummer" value="<?php echo html_special_chars($klantnummer);?>"></td>
</tr>
</table>
<input type="hidden" name="id" value="<?php echo html_special_chars($_GET['id']);?>">
<input type="submit" name="update" value="Update">
You had 7 td
's in one tr
and 8 in anoter
also:
1) dont forget to place your attribute values in quotes
2) use html_special_chars on output values, to prevent xss and breaking markup
来源:https://stackoverflow.com/questions/32050104/query-not-fully-showing