php - Can't put IP-address in database -
i'm trying put ip-address in database. if echo this:
echo $_server['remote_addr'];
but if i'm trying put in variable or in database gives nothing, in database says: null commands used that:
$ip = $_server['remote_addr']; mysql_query("update users set last_ip='".$ip."' id=".$row['id']) or die(mysql_error());
i don't know i'm doing wrong. can me please?
thanks!
you want make last_ip
column int(10) unsigned
, change update
be:
$sql = "update users set last_ip = inet_aton('$ip') id='{$row['id']}'";
then when selecting use:
$sql = "select inet_ntoa(last_ip) last_ip users";
this converts ip address integer efficient storage. more information please see mysql manual pages inet_aton()
, inet_ntoa()
.
otherwise if want stored text rather in efficient way can set last_ip
column char(16)
, continue use update
query posted in question.
Comments
Post a Comment