May 11, 2011

Can't put IP-address in database

Question by Bjorn Seigers

I’m trying to put an ip-address in my database.
If I do an echo like this:


But if I’m trying to put it in a variable or in the database it gives nothing, so in my database it says: NULL
The commands I used for that:

mysql_query("UPDATE users SET last_ip='".$ip."' WHERE id=".$row['id']) or die(mysql_error());

I don’t know what I’m doing wrong.
Can someone help me with this please?


Answer by Starx

Your code is correct and should work. Unless as commented by @wallyk, the data type of the ip field is unsupported one.

However, just to make sure wrap the WHERE condition in ' (Single Quote) and try.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!