[求助]表单问题求助 |
谁能帮我看看以下程序错误在哪儿,怎么修改呀
表 "const_skills" 用如下的 SQL 语句:
SQL> CREATE TABLE const_skills (
id int not null primary key,
value varchar(20) );
<?php
$myconn=mysql_connect("localhost","root","198265");
mysql_select_db("test",$myconn);
$skills = get_checkbox_labels("const_skills");
$html_skills = make_checkbox_html($skills, 3, 400, "skills[]");
?>
<html>
<body>
<br>
<form name="skills" method="POST" action="insertskills.php">
<? echo "$html_skills"; ?>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
<?php
function get_checkbox_labels($table_name) {
$arr = array();
$query = "SELECT * FROM $table_name";
$qid = mysql_query($query);
while($row= mysql_fetch_object($qid)) {
array_push($arr, $row);
}
return $arr;
}
function make_checkbox_html($arr, $num, $width, $name, $checked) {
$str = "";
$str .= "<table width="$width" border="0">";
$str .= "<tr>n";
if (count($arr) % $num != 0) {
$closingTR = true;
}
$i = 1;
if (isset($checked)) {
foreach ($arr as $ele) {
$str .= "<td><input type="checkbox" name="$name" value="$ele->id">";
foreach ($checked as $entry) {
if ($entry == $ele->value) {
$str .= "checked";
continue;
}
}
$str .= ">";
$str .= "$ele->value";
if ($i % $num == 0) {
$str .= "</tr>n<tr>";
} else {
$str .= "</td>n";
}
$i++;
}
} else {
foreach ($arr as $ele) {
$str .= "<td><input type="checkbox" name="$name" value="$ele->id">";
$str .= "$ele->value";
if ($i % $num == 0) {
$str .= "</tr>n<tr>";
} else {
$str .= "</td>n";
}
$i++;
}
}
if ($closingTR == true) {
$str .= "</tr></table>n";
} else {
$str .= "</table>n";
}
return $str;
}
?> |
|
|