提交按钮保持刷新页面

时间:2014-02-20 03:50:19

标签: php html

我知道这可能有点简单,但我看不出我的代码有什么问题,但它不起作用。单击提交按钮时,页面将继续刷新。我认为它没有输入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>

2 个答案:

答案 0 :(得分:3)

name="sub"

你在提交按钮代码中缺少=。

那应该有用

答案 1 :(得分:0)

替换此

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

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

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

如果答案是对的,请将其标记为答案....