Reputation: 5
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.
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
Thanks in advance :)
Upvotes: 0
Views: 1746
Reputation: 94
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.
Upvotes: 1
Reputation: 36
You could try echoing the mysql statement just before the mysql_query, i.e.
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.
Upvotes: 1
Reputation: 9351
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!";
}
Upvotes: 0
Reputation: 2719
For debug and simple work I recommended you store SQL query in variable.
$query = "INSERT INTO `follow` (`follower`, `following`, `follower_username`, `following_username`) VALUES ('".$userid."', '".$get_user_id."', '".$username."', '".$get_user."')";
echo "DEBUG:".$query;
mysql_query($query);
Upvotes: 0
Reputation: 4222
Try adding mysql_error
to your statement to find out what error is it so you can fix it:
mysql_query("INSERT INTO `follow` (`follower`, `following`, `follower_username`,
`following_username`) VALUES ('".$userid."', '".$get_user_id."', '".$username."',
'".$get_user."')") or die (mysql_error());
Upvotes: 0