我是一个完整的noob,已经达到了路障。我使用twitter引导,并试图通过php将表单模式发布到mysql服务器。这里是我的代码:twitter bootstrap模式不通过php发布
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;
}
?>
我检查查尔斯和奇怪我甚至不看一个POST发送〜45秒,直到我得到一个本地命令错误。因此,我是如何继续下去的。我确定我错过了几件事。任何建议表示赞赏。
P.S.我知道SQL数据库正在工作,因为它连接到我正在替换的旧的php站点。字段是文本等问题是与我的代码上面。
[获取萤火(http://getfirebug.com/),这将帮助你调试这些未来的问题。 – castis 2013-03-18 22:32:19
如果可以,请使用PDO。 – Xeoncross 2013-03-19 00:19:44
我从来没有写过任何PDO。我认为我的问题是表单甚至不会POST。但我对我的问题感到不知所措。 – Akito 2013-03-19 01:22:03