1

Im pulling out table information from a mysql db:

I need the buttons to select the information shown into a textfield, the below code works perfectly for the mobile_number but does not work for serial_number. both field types are varchars.

php to pull out info and html button

<?php while ($row = mysql_fetch_array($query)) { ?>
<td><?php echo $row['serial_number']; ?><input type="button" value="select" onclick="button(<?php echo $row['serial_number']; ?>)" /></td>
<td><?php echo $row['mobile_number']; ?><input type="button" value="select" onclick="button1(<?php echo $row['mobile_number']; ?>)" /></td>

text fields

<input type="text" id="textfield"/>
<input type="text" id="textfield2"/>

JS for the buttons

function button(text) {
     $("#textfield").val(text);
}
function button1(number) {
     $("#textfield2").val(number);
}

Thank you for your help in advance.

4

2 回答 2

2

您应该将文本包含在引号内,例如

onclick="button('<?php echo $row['serial_number']; ?>')"

手机也一样(它可能只是因为它是一个数字才起作用)

于 2013-11-05T09:41:20.753 回答
1

我会检查返回的列名是否与您引用的列名相同。除此之外,使用引号,如@sebapalus 建议的那样,并使用改进的功能sqli

于 2013-11-05T09:47:36.677 回答