我想创建接受用户条目的html页面并将其存储在数据库mysql中 然后另一个php页面显示表中的数据
用户将输入姓名并选择月份 该表应显示12个月的对应名称
我设法做到了这样
http://s9.postimg.org/po8kh6mz3/image.jpg
但我希望数据显示在不在彼此之下的单独行中
这是HTML页面看起来像
http://postimg.org/image/88e4cibqp/
每次用户输入不同的名称,我希望它在表格中以不同的行显示。
这是html页面的代码
<body>
<section class="container">
<div class="login">
<h1>ARABIAN HOMES</h1>
<form name="myForm" action="conn.php" method="post" onsubmit="return validateForm()">
<p>Name: <input type="text" name="adname" /> </p><br />
<h3>2014</h3>
<input name="jan" type="checkbox"/>Jan
<input name="feb" type="checkbox"/>Feb
<input name="mar" type="checkbox"/>Mar
<input name="apr" type="checkbox"/>Apr
<input name="may" type="checkbox"/>May
<input name="jun" type="checkbox"/>Jun
<input name="jul" type="checkbox"/>Jul
<input name="aug" type="checkbox"/>Aug
<input name="sep" type="checkbox"/>Sep
<input name="oct" type="checkbox"/>Oct
<input name="nov" type="checkbox"/>Nov
<input name="decmb" type="checkbox"/>Dec
<div style="text-align:center">
<input name="" type="submit" value="Submit" />
<input name="" type="button" value="View" onclick="window.location='view.php'"/>
然后我创建此页面以检查用户是否选中了复选框。 1表示检查0不是。并将其插入数据库
$adname = $_POST['adname'];
if (isset($_POST['jan'])) {
$jan=1;
} else {
$jan=0;
}
if (isset($_POST['feb'])) {
$feb=1;
} else {
$feb=0;
}
if (isset($_POST['mar'])) {
$mar=1;
} else {
$mar=0;
}
.
.//for all montha
$sql= "INSERT INTO ad (name, jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, decmb) VALUES ('$adname','$jan','$feb', '$mar', '$apr', '$may', '$jun', '$jul', '$aug', '$sep', '$oct' ,'$nov' ,'$decmb')
最后只显示名称,并在html表中显示复选框
$sql1=mysql_query("select name from ad where jan=1") or die(mysql_error());
$sql2=mysql_query("select name from ad where feb=1") or die(mysql_error());
$sql3=mysql_query("select name from ad where mar=1") or die(mysql_error());
$sql4=mysql_query("select name from ad where apr=1") or die(mysql_error());
$sql5=mysql_query("select name from ad where may=1") or die(mysql_error());
$sql6=mysql_query("select name from ad where jun=1") or die(mysql_error());
$sql7=mysql_query("select name from ad where jul=1") or die(mysql_error());
$sql8=mysql_query("select name from ad where aug=1") or die(mysql_error());
$sql9=mysql_query("select name from ad where sep=1") or die(mysql_error());
$sql10=mysql_query("select name from ad where oct=1") or die(mysql_error());
$sql11=mysql_query("select name from ad where nov=1") or die(mysql_error());
$sql12=mysql_query("select name from ad where decmb=1") or die(mysql_error());
echo "<table border=\"3\" width=\"100%\" align=\"center\"><tr><th height=\"40px\">January</th><th>February</th><th>March</th><th>April</th><th>May</th> <th>June</th><th>July</th><th>August</th><th>September</th><th>October</th> <th>November</th><th>December</th></tr>";
echo "<tr valign=\"top\" align=\"center\"><td>";while($row1=mysql_fetch_array($sql1))
{echo "{$row1['name']}</br>";}
echo "</td>";
echo "<td>";while($row2=mysql_fetch_array($sql2))
{echo "{$row2['name']}</br>";}
echo "</td>";
echo "<td>";while($row3=mysql_fetch_array($sql3))
{echo "{$row3['name']}</br>";}
echo "</td>";
echo "<td>";while($row4=mysql_fetch_array($sql4))
{echo "{$row4['name']}</br>";}
echo "</td>";
echo "<td>";while($row5=mysql_fetch_array($sql5))
{echo "{$row5['name']}</br>";}
echo "</td>";
echo "<td>";while($row6=mysql_fetch_array($sql6))
{echo "{$row6['name']}</br>";}
echo "</td>";
echo "<td>";while($row7=mysql_fetch_array($sql7))
{echo "{$row7['name']}</br>";}
echo "</td>";
echo "<td>";while($row8=mysql_fetch_array($sql8))
{echo "{$row8['name']}</br>";}
echo "</td>";
echo "<td>";while($row9=mysql_fetch_array($sql9))
{echo "{$row9['name']}</br>";}
echo "</td>";
echo "<td>";while($row10=mysql_fetch_array($sql10))
{echo "{$row10['name']}</br>";}
echo "</td>";
echo "<td>";while($row11=mysql_fetch_array($sql11))
{echo "{$row11['name']}</br>";}
echo "</td>";
echo "<td>";while($row12=mysql_fetch_array($sql12))
{echo "{$row12['name']}</tr></br>";}
echo "</td>";
echo "</table>";
为此道歉,我知道我对此并不擅长,并且有一种简单的方法可以避免这个长代码。但是我希望你能从中获得的唯一帮助是,所有月份的信息都会在表格中以不同的行显示
提前致谢