0

我是一个完全的菜鸟,遇到了障碍。我正在使用 twitter 引导程序,并试图通过 php 将表单模式发布到 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(提交表单.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;
}
?>

我正在检查查尔斯,奇怪的是,在我收到本地命令错误之前,我什至没有看到大约 45 秒的 POST 发送。因此,我不知道如何进行。我确定我错过了几件事。任何建议表示赞赏。

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

4

2 回答 2

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" />
于 2013-03-19T04:21:02.830 回答
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>标签具有输入类型。这应该发布您的代码。为什么你exit;的PHP文件上有?

于 2013-03-18T22:18:17.460 回答