2013-01-02 54 views
1

我試圖在我的數據庫表choice中保存單選按鈕的值。我收到消息Data saved successfully,但表中沒有存儲值。無法存儲表中的單選按鈕值

形式:

<form id="myForm" method="post" action=""> 
<div data-role="fieldcontain"> 
       <fieldset data-role="controlgroup"> 
        <center<legend>Choose in which category you'd like to be included</legend></center> 
        <p><input type="radio" name="choice[]" value="player" id="player" class="custom" /> 
        <label for="player">Player</label> 
        <input type="radio" name="choice[]" value="coach" id="coach" class="custom" /> 
        <label for="coach">Coach</label> 
        <input type="radio" name="choice[]" value="supporter" id="supporter" class="custom" /> 
        <label for="supporter">Supporter</label> 
        <input type="radio" name="choice[]" value="sponsor" id="sponsor" class="custom" /> 
        <label for="sponsor">Sponsor</label> 
        <input type="radio" name="choice[]" value="alumni" id="alumni" class="custom" /> 
        <label for="alumni">Alumni</label> 
        <input type="radio" name="choice[]" value="other" id="o" class="custom" /> 
        <label for="o">Other</label> 

       </fieldset> 
      </div> 
<div data-role="fieldcontain"> 
    <label for="name">Please enter your name:</label> 
    <input type="text" name="name" id="name" class="required" value="" autocomplete="off" /><br /> 
    <label for="email">Please enter your e-mail:</label> 
    <input type="text" name="email" id="email" value="" class="required" autocomplete="off" /><br /> 
    <label for="phone">Please enter your phone number:</label> 
    <input type="number" name="phone" id="phone" value="" class="required" autocomplete="off" /> 

<br><br>  
<label for="other">Other comments</label> 
<textarea name="other" id="other" autocomplete="off" placeholder="Anything else you'd like to add?"> 
</textarea> 
<p><strong id="error"></strong></p> 
<br><br> 
<input type="submit" id="save" name="save" value="Submit Form" /> 
<p id="response"></p> 
</form> 
</body> 
</html> 

PHP:

<?php 
$mysqli = new mysqli('localhost', 'root', '', 'E-mail list'); 
/* check connection */ 
if ($mysqli->connect_errno) { 
printf("Connect failed: %s\n", $mysqli->connect_error); 
exit(); 
} 
if(isset($_POST['save'])) 
{ 
$name = $mysqli->real_escape_string($_POST['name']); 
$email = $mysqli->real_escape_string($_POST['email']); 
$phone = $mysqli->real_escape_string($_POST['phone']); 
$other = $mysqli->real_escape_string($_POST['other']); 
$choice = $mysqli->real_escape_string($_POST['choice']); 
$query = "INSERT INTO Players (`name`,`email`,`phone`,`other`,`choice`) VALUES ('".$name."','".$email."','".$phone."','".$other."','".$choice."')"; 
if($mysqli->query($query)) 
{ 
echo 'Data Saved Successfully.'; 
} 
else 
{ 
echo 'Cannot save data.'; 
} 
} 
?> 
+0

是什麼mysql數據類型的選擇?另外,請在您的文件中回顯$ query,並讓我們知道打印到屏幕上的結果。看看有什麼價值,如果有的話,選擇正在變得有用。很明顯,爲了執行該部分而獲得正確的價值。 – donlaur

+0

它是varchar(15) –

+0

我在$查詢做了一個回聲,它顯示沒有值的選擇。 –

回答

1

var_dump($_POST)到乾枯什麼數據洪水

還有一兩件事,以檢查其保存或提交。?在$_POST['save']

編輯

得到您的完整形式之後 - 錯誤在於你center標籤

變化<center<legend> TO <center><legend>

錯誤 - ↑在這個標籤中

+0

不,不會這樣做:( –

+0

@PAHemingstam plz現在檢查我的編輯答案 – swapnesh

+0

謝謝!我收到此消息: {[「name」] => string(1)「q」[「email」] => string(1)「q」[「phone」] => string(1)「q」[「other」] => string(1)「q」[「save」] => string(11) } –