<?php
if (mysqli_num_rows($result) > 0 ){
while($row = mysqli_fetch_assoc($result)){
$fName = $row['firstName'];
$sName = $row["lastName"];
$email = $row["email"];
$address1 = $row['address1'];
$address2 = $row["address2"];
$address3 = $row["address3"];
$city = $row["city"];
$county = $row["county"];
$postcode = $row["postcode"];
$country = $row["country"];
$mobile = $row["mobile"];
$homeNum = $row["home"];
}
}
?>
<?php
<label for="subject">Address 1:</label>
<input type="text" id="lname" name="address1" size ="40" value=<?php echo $address1 ?>> <br>
我希望表单具有db中的值“address1”。它的意思是从表格值的db行“address1”中回显“27 Lisburn Road”,但是,网页上的表单中只显示“27”。
当我回复$ address1不在表格中时,在网页上输出完整的地址(即 - 利斯本路27号)。
总而言之,我很困惑,因为当我回显$ address1作为表格值时,网页上只输出“27”,但是当$ address1被回显时输出“27 Lisburn Road”形式。< / p>
任何人都知道如何解决这个问题?
谢谢!
答案 0 :(得分:0)
您是否确保在mysql表中将地址1的表数据设置为CHAR而不是整数或其他任何内容?这可能是原因。
试试这个:
<?php
if (mysqli_num_rows($result) > 0 ){
while($row = mysqli_fetch_assoc($result)){
$fName = $row["firstName"];
$sName = $row["lastName"];
$email = $row["email"];
$address1 = $row["address1"];
$address2 = $row["address2"];
$address3 = $row["address3"];
$city = $row["city"];
$county = $row["county"];
$postcode = $row["postcode"];
$country = $row["country"];
$mobile = $row["mobile"];
$homeNum = $row["home"];
}
?>
<label for="subject">Address 1:</label>
<input type="text" id="lname" name="address1" size ="40" value="<?php echo $address1; ?>"> <br>
<?php } else { ?>
<label for="subject">Address 1:</label>
<input type="text" id="lname" name="address1" size ="40" value="test"> <br>
<?php } ?>
如果您在结束PHP之前不关闭语句,那么您的PHP将具有HTML的独立执行上下文?&gt;
答案 1 :(得分:0)
您可能想要查看是否应删除任何空格或仅trim($address1)
。