簡體   English   中英

PHP:String不會插入MySQL數據庫

[英]PHP: String won't insert into MySQL database

我的字符串字段不會插入到我的數據庫中。

(列follower_username和following_username,它們是VARCHAR(200)不插入):follower和以下列值插入工作。

mysql_query("INSERT INTO `follow` (`follower`, `following`, `follower_username`, `following_username`) VALUES ('".$userid."', '".$get_user_id."', '".$username."', '".$get_user."')");

字符串:

$get_user = mysql_real_escape_string($row['username']);
$get_user_id = (int)mysql_real_escape_string($row['id']);
$userid = (int)mysql_real_escape_string($user_data['id']);
$username = mysql_real_escape_string($user_data['username']);

我不知道該怎么做,無論是PHP還是數據庫本身:S

提前致謝 :)

嘗試這個 :

mysql_query("INSERT INTO follow (`follower`, `following`, `follower_username`, `following_username`) VALUES ('".$userid."', '".$get_user_id."', '".$username."', '".$get_user."')");

不要在表名周圍使用單引號。

您可以嘗試在mysql_query之前回顯mysql語句,即

echo "INSERT INTO `follow` (`follower`, `following`, `follower_username`, `following_username`) VALUES ('".$userid."', '".$get_user_id."', '".$username."', '".$get_user."')";

並檢查字符串是否符合您的預期。 如果它是您所期望的,請嘗試手動復制字符串並將其粘貼到mysql控制台中,看看是否發生任何錯誤。

嘗試將mysql_error添加到您的語句中以找出它是什么錯誤,以便您可以修復它:

mysql_query("INSERT INTO `follow` (`follower`, `following`, `follower_username`,
`following_username`) VALUES ('".$userid."', '".$get_user_id."', '".$username."',   
'".$get_user."')") or die (mysql_error());

對於調試和簡單的工作,我建議您將SQL查詢存儲在變量中。

$query  = "INSERT INTO `follow` (`follower`, `following`, `follower_username`, `following_username`) VALUES ('".$userid."', '".$get_user_id."', '".$username."', '".$get_user."')";
echo "DEBUG:".$query;
mysql_query($query);

嘗試這個:

 $objQuery = mysql_query("INSERT INTO `follow` (`follower`, `following`, `follower_username`,
    `following_username`) VALUES ($userid, $get_user_id, '".$username."',   
    '".$get_user."')") or die (mysql_error());

if(!$objQuery){
 echo "something went wrong!";
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM