2014-11-20 43 views
0

我不知道什麼是錯誤的,目前沒有錯誤,當我去我的建議頁,所以我不知道什麼是錯的,有什麼想法?PHP插入建議到SQL表中

//index.php 

<form name="suggestion" action="http://example.com/suggestions.php" method="POST"> 
<font style="font-family: arial; color:#3f3f3f; font-size:15px;">Provide me with a URL to one or multiple songs that you want on the website!</font> <br><br><input style="width:243px;" type="text" name="suggestion"><br> 
<br> 
<input value="Submit" type="submit"> 
</form> 


//suggestions.php 

<?php 
$conn=mysql_connect("localhost", "u611142741_list", "[REDACTED]"); 
mysql_select_db("u611142741_sugge", $conn); 

// If the form has been submitted 

$suggestion = mysql_real_escape_string($_POST['suggestion']); 
$ip = $_SERVER['REMOTE_ADDR']; 



    // Build an sql statment to add the student details 
    $sql="INSERT INTO suggestions 

(Suggestion,IP Address) VALUES 

('$suggestion','$ip')"; 
    $result = mysql_query($sql,$conn); 


// close connection 
mysql_close($conn); 
?> 
+0

您的字段名稱是否真的帶有空格的「IP地址」? – 2014-11-20 18:50:11

+0

確實。 「IP地址」 – user4191887 2014-11-20 18:51:28

回答

0

您的字段名稱中有一個空格,並且需要加引號。你現在擁有什麼;

INSERT INTO suggestions (Suggestion,IP Address) VALUES ('$suggestion','$ip') 

...但字段名IP Address包含空格,需要使用反引號,導致在MySQL中被引用,正常;

INSERT INTO suggestions (Suggestion, `IP Address`) VALUES ('$suggestion','$ip') 
+0

好吧,現在屬性出現在我的sql表中,但建議是空白的,你知道什麼是錯的嗎? – user4191887 2014-11-20 19:05:34

+0

@ user4191887難道你的整個表單的命名與你的文本字段是一樣的嗎? – 2014-11-20 19:07:26

+0

Errm ..我已將表單的名稱更改爲「建議」,但它仍未出現。 – user4191887 2014-11-20 19:37:11

0

你可以試試這個:

$sql="INSERT INTO suggestions 

(`Suggestion`,`IP Address`) VALUES 

('$suggestion','$ip')"; 

讓我知道,如果作品。