海蘭傢伙,致命錯誤:調用未定義功能reg_form()在C: XAMPP htdocs中 PHP PHP BEGINNING 5 mysql的 form_test.php上線18
我是新來的PHP,該我指的是PHP書 - 「可以在實際函數定義出現在代碼中之前調用函數」。在下面的代碼中,我正在調用_reg_form(); _函數在下面定義之前,但我得到的錯誤。我究竟做錯了什麼。
感謝您的關注。
<?php
include('common_db.inc');
include('validation.php');
if(!$link=db_connect()) die(sql_error());
if($_POST['submit'])
{
$userid = $_POST['userid'];
$userpassword=$_POST['userpassword'];
$username=$_POST['username'];
$userposition = $_POST['userposition'];
$useremail=$_POST['useremail'];
$userprofile=$_POST['userprofile'];
$result=validate();
if($result==0)
{
reg_form();
}
else
{
mysql_query("INSERT INTO user VALUES(NULL,'$userid',Password('$userpassword'),'$username','$userposition','$useremail','$userprofile')",$link);
}
}
else
{
?>
<?php
function reg_form()
{
echo "<table border='1'>
<form action='form_test.php' method='post'>
<tr><td>Desired ID:</td>
<td><input type='text' size='12' name='userid' /></td></tr>
<tr><td>Desired Password:</td>
<td><input type='password' size='12' name='userpassword' /></td></tr>
<tr><td><input type='hidden' name='submit' value='true' />
<input type='submit' value='Submit' />
<input type='reset' value='Reset' /></td></tr>
</form>
</table>";
}
reg_form();
?>
<?php
}
?>
爲什麼不先定義函數?我不確定你在做什麼是可能的(我猜不是),但那不是很重要,因爲它在任何情況下都會是可怕的編碼風格 – Hannes 2011-01-05 13:16:40