2013-03-28 108 views
2

我試圖發佈數據並將其放入msql數據庫,但是當我把print_r($ _ POST);它顯示數組爲空。我知道它獲得正確的價值,但它不張貼HTML form not POSTing

<!DOCTYPE html> 

<html> 

<head> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
     <script src="Scripts/menu.js"></script> 
     <script src="Scripts/signup.js"></script> 

<link rel='stylesheet' href='CSS/index.css'> 


</head> 

<body> 

<img src="wc.png" id="wc"> 

<img src='restaurant.jpg' id="restaurant"> 
<img src='map.jpg' id="map"> 
<img src='mail.jpg' id="mail"> 
<img src='people.jpg' id="people"> 

<div id="window"> <div id="membersWindow"> <input type="text" id="signupUsername" value="name" placeholder="Username"> 

<form action="/signup.php" method="post"> 
<input type="password" id="signupPassword" placeholder="Password"> 

<input type="text" id="signupEmail" placeholder="Email"> 

<input type="text" id="signupphoneNumber" placeholder="Phone Number"> 

<iframe src="useragreement.html" id="userAgreement"> </iframe> 

<input type="submit" id="signupSubmit"> 
</div> 

</form> 

<div id="restaurantWindow"> Restaurant Window </div> 

<!--- <div id="mapWindow"> <iframe src="https://maps.google.com/?ie=UTF8&amp;ll=29.817178,-95.401291&amp;spn=0.689868,1.256561&amp;t=h&amp;z=10&amp;output=embed"></iframe> 
</div> ---> 

<div id="mailWindow"> Mail Window </div> 

</div> 

<div id="banner"> <h1> Wolfeboro Connection </h1> </div> 

</body> 

</html> 

下面是獲取帖子,但它顯示數組()爲空的PHP頁面。還沒有任何錯誤報告。

<?php 
error_log(E_ALL); 

if(isset($_POST)) echo "NO POST<BR>"; 
print_r($_POST); 



include("connection.php"); 



$stmt = $db->stmt_init(); 

if($stmt->prepare("INSERT INTO users (BusinessName, Password, Phone, Email) VALUES (?, ?, ?, ?)")) { 

$stmt->execute(); 
$stmt->close(); 

} 



?> 


$(function() 
{ 
alert($("#signupUsername").val()); 

$("#signupSubmit").click(function() { 
alert("posting "+$("#signupUsername").val()); 

$.post("../signup.php", 
    { username: $("#signupUsername").val(), 
    password: $("#signupPassword").val(), 
    phonenumber: $("#signupphoneNumber").val(),  
    email: $("#signupEmail").val() 
    }) 
    .done(function(r) 
    { 
    alert("done"); 
    }) 
    .fail(funciton() 
    { 
    alert("fail"); 
    }); 
}); 
alert("loaded"); 

}); 
+0

您還可以將u爲Firefox提供「HTTPFox」-AddOn以獲取所有請求,包括所有GET/POST信息以進行調試。這是非常有用的:) – 2013-03-28 00:10:42

+0

jQuery和AJAX在哪裏發揮作用?這僅僅是一個基本的HTML表單。 – 2013-03-28 00:17:49

+0

什麼是輸出 – 75inchpianist 2013-03-28 00:24:58

回答

10

<input>標籤需要name屬性。它會被用來爲索引在你$_POST,所以,這個輸入:

<input name="some" type="text"/> 

會產生:

$_POST['some'] 

http://www.w3schools.com/php/php_post.asp

+0

它的工作感謝所有 – 2013-03-28 00:14:09

2

你必須給所有input SA name屬性,該屬性將值添加到數組中:

<form action="/signup.php" method="post"> 
    <input type="password" id="signupPassword" placeholder="Password"> 

    <input type="text" name="signupEmail" placeholder="Email"> 

    <input type="text" name="signupphoneNumber" placeholder="Phone Number"> 

    <input type="submit" name="signupSubmit"> 
</form>