2013-03-09 143 views
-1

我的表单没有提交,我的数据库插入类的作品,我已经测试。但是我的表单似乎不想提交或发布我的表单中的值。有没有我遗漏的东西?表单不提交HTML php

<form name="form1" method="post" action="sub_newsletter.php" enctype="multipart/form-data"> 
<table border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td colspan="2">Newsletter</td> 
</tr> 
<tr> 
<td>Name : </td> 
<td><input name="name" type="text"></td> 
</tr> 
<tr> 
<td>Email : </td> 
<td><input name="email" type="text"></td> 
</tr> 
<tr> 
<td> <input type="text" name="check_spam" id="check_spam" size="30" style="display:none;" /> </td> 
<td>&nbsp;</td> 
</tr> 
<tr> 
<td colspan="2" align="center"><input type="image" name="submit" src="images/sub.jpg" style="width:180px; height:70px;"></td> 
</tr> 
</form> 
</table> 

我提交脚本

<?php 
include('includes/database.php'); 
include('includes/settings.php'); 
include('includes/newsletter.php'); 

if (isset($_POST['submit'])){ 
//to check if posting 
echo $username=rtrim($_POST['name']); 
echo $myemail=rtrim($_POST['email']); 
// 
$check=$_POST['check_spam']; 
if(!empty($check)){ echo "You are spam"; } else{ 
$username=rtrim($_POST['name']); 
$myemail=rtrim($_POST['email']); 
$news = new Newsletter(); 
$new->first_name=$username; 
$new->email=$myemail; 
$new->create(); 
echo "<script>alert(\"Thank you for your subscription\"); </script>"; 
echo "<script>window.location.replace(\"index.html\"); </script>"; 
} 
} 
?> 
+0

其中? – Vimalnath 2013-03-09 18:07:10

+0

这是因为你正在使用和图像按钮 - “'用一个提交按钮替换它 - ''并且简单地使用CSS来增强它的外观。一个图像按钮在你点击它时会传递X和Y坐标,并且你提到的条件 - 'if(isset($ _ POST ['submit'])){}'永远不会被满足。 – Lion 2013-03-09 18:11:54

回答

1

你显然错过了提交按钮

<input type="submit" name="submit"> 

既然你已经一个与名字段,只要改变它,或者使用不同的名称。

+0

不要忘记给一个名称属性。否则将不会在服务器上访问。 – Lion 2013-03-09 18:20:30

+0

@Lion yup,已更新。 – Hast 2013-03-09 18:24:12