1 2 3 4 5 6 下一页 假设你对表单很熟悉,这是一个相当简单的脚本。我们根据html页面设计了一个表单,它在提交后调用 add2tbl.PHP3脚本。现在,表单与MySQL表相对应由4个字段组成:index number,FirstName,LastName和 FreeText。注意在这个表单中字段名字与MySQL表中字段名一样,但这只是为了方便起见而不是必须。 我们再一次使用了include命令<? include ('links.x');?>(象在前面所解释的)来增加链接。 让我们看一下add2tbl.php3脚本: <html> <body> <? if ($UserName) { mysql_connect() or die ("Problem connecting to DataBase"); $query = "insert into tbl values ('$idx','$UserName','$LastName','$FreeText')"; $result = mysql_db_query("example", $query); echo "Data inserted. new table:<br><p></p>"; $query = "SELECT * FROM tbl"; $result = mysql_db_query("example", $query); if ($result) { echo "<table width=90% align=center border=1><tr> <td align=center bgcolor=#00FFFF>idx</td> <td align=center bgcolor=#00FFFF>User Name</td> <td align=center bgcolor=#00FFFF>Last Name</td> <td align=center bgcolor=#00FFFF>Free Text</td> </tr>"; while ($r = mysql_fetch_array($result)) { $idx = $r["idx"]; $user = $r["UserName"]; $last = $r["LastName"]; $free = $r["FreeText"]; echo "<tr> <td>$idx</td> <td>$user</td> <td>$last</td> <td>$free</td> </tr>"; } // while循环结束 echo "</table>"; } else { echo "No data."; } // if结束($result) } else { echo "No UserName Entered. Please go back and reenter UserName"; } // if结束($UserName) echo "<p></p>"; include ('links.x'); ?> </body> </html> 解释: (责任编辑:admin) |