2014-11-20 78 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')"; 

让我知道,如果作品。