2014-02-20 44 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" /> 

....