简体   繁体   English

twitter bootstrap modal不能通过php发布

[英]twitter bootstrap modal not posting via php

I'm a complete noob that has hit a road block. 我是一个遇到障碍的完全菜鸟。 I'm using twitter bootstrap and am attempting to POST a form modal to mysql server via php. 我正在使用twitter bootstrap,并尝试通过php将表单模式发布到mysql服务器。 Here is my code: 这是我的代码:

HTML (index.html): 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(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;
}
?>

I'm checking Charles and oddly I don't even see a POST sent for ~45 seconds until I get a local command error. 我正在检查Charles,奇怪的是,直到收到本地命令错误,我什至没有看到POST发送约45秒。 As such, I'm a loss on how to proceed. 因此,我对如何进行一无所知。 I'm sure I'm missing a couple of things. 我确定我错过了几件事。 Any advice is appreciated. 任何建议表示赞赏。

PS I know the SQL database is working since it connects to the old php site I'm looking to replace. PS我知道SQL数据库正在工作,因为它已连接到我要替换的旧php网站。 Fields are text, etc. The issue is with my code above. 字段是文本等。问题出在我上面的代码中。

You're missing the closing } for your if(strlen(.... 你错过截止}if(strlen(....

Updated: 更新:

HTML 的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>

You can't have an <a> tag have an input type. 您不能让<a>标记具有输入类型。 This should post your code. 这应该发布您的代码。 Why do you have exit; 你为什么要exit; on your PHP file? 在您的PHP文件上?

I think the problem is with the submit button, instead of 我认为问题在于提交按钮,而不是

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

Use 采用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM