2014-02-20 275 views
0

我知道這可能有點簡單,但我看不出我的代碼有任何問題,但它不起作用。當點擊提交按鈕時,頁面會一直刷新。我認爲這不是輸入if(isset($_POST['sub']))的代碼。這裏是我的代碼:提交按鈕不斷刷新頁面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Add Client</title> 
</head> 

<body> 
<?php 
require("dbconnect.php"); 
?> 
&nbsp; 
&nbsp; 
<form method="post"> 
<center> 
<h1>Add Client</h1> 
<table> 
<tr><td>Client Name</td><td><input name="cname" type="text" /></td></tr> 
<tr><td>Client Category</td><td><input name="cat" type="text" /></td></tr> 
<tr><td>Client Address</td><td><input name"add" type="text" /></td></tr> 
<tr><td>Client City</td><td><input name="city" type="text" /></td></tr> 
<tr><td>Contact Person</td><td><input name="cper" type="text" /></td></tr> 
<tr><td>Contact Details</td><td><input name="cdet" type="text" /></td></tr> 
<tr><td>Sales Territory</td><td> 
<?php 
$a=mysql_query("select `sales-territory-no`, `sales-territory-name` from `sales-territory`") or die(mysql_error()); 
echo"<select name='terr'>"; 
while($b=mysql_fetch_array($a)) 
{ 
    echo "<option value='".$b['sales-territory-no']."'>".$b['sales-territory-name']."</option>"; 
} 
echo "</select>"; 
?> 
</td></tr> 
<tr><td>Sales Person ID</td><td> 
<?php 
$c=mysql_query("select * from `sales`") or die(mysql_error()); 
echo"<select name='sales'>"; 
while($d=mysql_fetch_array($c)) 
{ 
    echo "<option value='".$d['sales-no']."'>".$d['firstname'].' '.$d['lastname']."</option>"; 
} 
echo "</select>"; 
?> 
</td></tr> 
</table> 
<br /> 
<input type="submit" name"sub" value="Submit" /> 
</center> 
</form> 
<?php 
if(isset($_POST['sub'])) 
{ 
    echo "<script type=\"text/javascript\">"; 
    echo "alert(\"Hello!\");"; 
    echo "</script>"; 
} 
?> 
</body> 
</html> 

回答

3
name="sub" 

你錯過了在提交按鈕的代碼=。

這應該工作

+0

我可以」我相信我沒有看到。 -___- – xjshiya

+0

有時你只需要第二雙眼睛;) – Chitowns24

0

如果這個答案是正確的,那麼請把它標記爲一個答案替換此

<input type="submit" name="sub" value="Submit" /> 

<input type="submit" id="sub" value="Submit" /> or 

<input type="submit" name="sub" value="Submit" /> 

....