twitter bootstrap模式不通过php发布

时间:2013-03-18 22:14:36

标签: php twitter-bootstrap

我是一个已经遇到路障的完整菜鸟。我正在使用twitter bootstrap并尝试通过php将表单模式POST到mysql服务器。这是我的代码:

HTML(index.html):

<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="ModalLabel">****</h3>
  </div>
  <div class="modal-body">
    <form id="modal-form" accept-charset="UTF-8" method="POST" action="submitform.php" data-remote="true" >
      <p>Give us your email, and we'll send you an invitation</p>
      <fieldset>
    <input type="text" name="email" id="email" class="reqInput" placeholder="Email Address">
    <input type="text" name="name" id="name" class="reqInput" placeholder="Full Name">
    <input type="text" name="company" id="company" class="reqInput" placeholder="Company">
    <input type="text" name="title" id="title" class="reqInput" placeholder="Title">
      </fieldset>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <a id="modal-form-submit" type="submit" name="submit" class="btn btn-primary" href"#">Submit</a>
  </div>
</form>
</div>

PHP(submitform.php):

<?php
$host="localhost"; // Host name 
$username="***"; // Mysql username 
$password="***"; // Mysql password 
$db_name="users"; // Database name 
$tbl_name="userRequests"; // Table name

// Connect to server and select databse.
$con = mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$name=$_POST['name']; 
$company=$_POST['company'];
$email=$_POST['email'];
$title=$_POST['title'];

if(strlen($name) > 1 && strpos($email, "@")){

// To protect MySQL injection (more detail about MySQL injection)
$name = mysql_real_escape_string(stripslashes($name));
$company = mysql_real_escape_string(stripslashes($company));
$email = mysql_real_escape_string(stripslashes($email));
$title = mysql_real_escape_string(stripslashes($title));

$sql="INSERT INTO $tbl_name (FullName, Company, Email, Title) VALUES ('$name', '$company', '$email', '$title')";

exit;
}
?>

我正在检查Charles,奇怪的是我甚至没有看到发送的POST约45秒,直到我收到本地命令错误。因此,我对如何进行感到失望。我敢肯定我错过了几件事。任何建议都表示赞赏。

P.S。我知道SQL数据库正在工作,因为它连接到我想要替换的旧php站点。字段是文本等。问题出在上面的代码中。

2 个答案:

答案 0 :(得分:0)

您错过了}

的结束if(strlen(....

更新:

HTML

<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="ModalLabel">****</h3>
  </div>
  <div class="modal-body">
    <form id="modal-form" accept-charset="UTF-8" method="POST" action="submitform.php" data-remote="true" >
      <p>Give us your email, and we'll send you an invitation</p>
      <fieldset>
    <input type="text" name="email" id="email" class="reqInput" placeholder="Email Address">
    <input type="text" name="name" id="name" class="reqInput" placeholder="Full Name">
    <input type="text" name="company" id="company" class="reqInput" placeholder="Company">
    <input type="text" name="title" id="title" class="reqInput" placeholder="Title">
      </fieldset>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <input id="modal-form-submit" type="submit" name="submit" class="btn btn-primary" href"#" value="Submit"/>
  </div>
</form>
</div>

您不能让<a>标记具有输入类型。这应该发布你的代码。为什么PHP文件上有exit;

答案 1 :(得分:0)

我认为问题出在提交按钮上,而不是

<a id="modal-form-submit" type="submit" name="submit" class="btn btn-primary" href"#">Submit</a>

使用

<input type="submit" id="modal-form-submit" name="submit" class="btn btn-primary" />