简体   繁体   English

PHP:String不会插入MySQL数据库

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

My string field won't insert into my database. 我的字符串字段不会插入到我的数据库中。

(The columns follower_username and following_username they are VARCHAR(200) don't insert ) The: follower and following column values insert work. (列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."')");

Strings: 字符串:

$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']);

I have no idea what to do, whether it is the PHP or the database itself :S 我不知道该怎么做,无论是PHP还是数据库本身:S

Thanks in advance :) 提前致谢 :)

try this : 尝试这个 :

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

don't use single quotes around table name. 不要在表名周围使用单引号。

You could try echoing the mysql statement just before the mysql_query, ie 您可以尝试在mysql_query之前回显mysql语句,即

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

and check if the string is what you expected it to be. 并检查字符串是否符合您的预期。 If it is what you expected, try manually copying the string and pasting it into the mysql console and see if any errors occur. 如果它是您所期望的,请尝试手动复制字符串并将其粘贴到mysql控制台中,看看是否发生任何错误。

Try adding mysql_error to your statement to find out what error is it so you can fix it: 尝试将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());

For debug and simple work I recommended you store SQL query in variable. 对于调试和简单的工作,我建议您将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);

Try this: 尝试这个:

 $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