nclemale 03-02-2010, 08:42 PM i have tried a few ways and can not get the ip address to insert in database.
added all this to register file
$ip = getip();
$ip = explode(".",$ip);
$data['ip'] = $user->escape(post('ip'));
this is my ip function
///////////////////////////////////////////GET IP
function getip()
{
if (getenv('HTTP_X_FORWARDED_FOR'))
{
$ip=getenv('HTTP_X_FORWARDED_FOR');
}
else
{
$ip=getenv('REMOTE_ADDR');
}
return $ip;
}
and this is my insert code
$sql = "INSERT INTO `user` (
`username` ,`ip` ,`password` ,`day` ,`month` ,
`year` ,`gender` ,`country` ,`email` ,
`referrer` ,`about` ,`confirmation`
)
VALUES (
'{$username}', '{$ip}', '{$password}', '{$day}', '{$month}',
'{$year}', '{$gender}', '{$country}', '{$email}',
'{$referrer}', '{$about}', '{$confirmation}')";
the last code/ file also has
$ip = getip();
$ip = explode(".",$ip);
anyone help me.
angst 03-02-2010, 08:43 PM what type of field are you trying to insert it into? also do you get any errors?
Fou-Lu 03-02-2010, 08:49 PM While the datatype is very much important, I'm curious about this one as well:
$ip = getip();
$ip = explode(".",$ip);
Assuming that is used prior to the insertion, you now have $ip as an array of 4 items or one (depending on if IPv6 support is available or not). I doubt you'll need the explode call on there as well, the ip address is a string; if you want to convert it to a number, use the ip2long and long2ip functions.
nclemale 03-02-2010, 08:51 PM no no errors. every other field enters the value thats inputted except the ip .
i tried
`ip` varchar(20) NOT NULL DEFAULT '',
have also tried
`ip` int(20) NOT NULL DEFAULT '',
Fou-Lu 03-02-2010, 08:54 PM no no errors. every other field enters the value thats inputted except the ip .
i tried
`ip` varchar(20) NOT NULL DEFAULT '',
have also tried
`ip` int(20) NOT NULL DEFAULT '',
You may have missed mine, see if its an array since that won't be insertable.
As for you're datatype, make sure its a varchar(15) or char(15) at minimum. Don't use an integer unless you're planning on storing the long number, and sprintf it with a %u modifier to force an unsigned integer from PHP.
angst 03-02-2010, 08:54 PM well int. wont do it unless you convert using the ip2long() as Fou-Lu mentioned.
but it does look like maybe your trying to insert an array.
just out of curiosity, why are you exploding the ip anyway?
nclemale 03-02-2010, 08:58 PM no idea . am not an expert .am just using some code off another script to make this ip insert into database .
thought it may play a part in getting the info that i need to insert it .
angst 03-02-2010, 09:00 PM ah ok,
well remove the explode code, make your field a varchar ( as Fou-Lu said above ),
and do a normal insert. that should do it ;)
nclemale 03-02-2010, 09:01 PM now your confusing me. normal insert ? what other kind is there . ?
Fou-Lu 03-02-2010, 09:05 PM now your confusing me. normal insert ? what other kind is there . ?
O.o
Just normal.
The problem is that $ip is an array so its considered complex, something that a database cannot handle. You would need to flatten the complex data back into a string (or just not explode it at all), or serialize the data so its representable as a string.
angst 03-02-2010, 09:06 PM in short,
just comment out/remove this code and test it:
$ip = explode(".",$ip);
$data['ip'] = $user->escape(post('ip'));
nclemale 03-02-2010, 09:07 PM right i have took explode out and changed the type to varchar(16).
still dont work .
angst 03-02-2010, 09:09 PM try this;
$sql = "INSERT INTO `user` (
`username` ,`ip` ,`password` ,`day` ,`month` ,
`year` ,`gender` ,`country` ,`email` ,
`referrer` ,`about` ,`confirmation`
)
VALUES (
'{$username}', '{$_SERVER['REMOTE_ADDR']}', '{$password}', '{$day}', '{$month}',
'{$year}', '{$gender}', '{$country}', '{$email}',
'{$referrer}', '{$about}', '{$confirmation}')";
if that fails, echo/print $sql and post the result.
nclemale 03-02-2010, 09:12 PM $data['ip'] = $user->escape(post('ip'));
is part of the register as i have the same for
$data['username'] = $user->escape(post('username'));
$data['password'] = $user->escape(post('password'));
$data['cpassword'] = $user->escape(post('cpassword'));
$data['day'] = $user->escape(post('day'));
$data['month'] = $user->escape(post('month'));
$data['year'] = $user->escape(post('year'));
$data['gender'] = $user->escape(post('gender'));
$data['country'] = $user->escape(post('country'));
$data['email'] = $user->escape(post('email'));
$data['referrer'] = $user->escape(post('referrer'));
$data['about'] = $user->escape(post('about'));
it still dosnt work anyway with all those removed. as i say i have tried a few things before asking for help
angst 03-02-2010, 09:14 PM right, but can you post the echo'd $sql ?
so we can see whats in the actual query being sent to mysql
nclemale 03-02-2010, 09:17 PM angst thats worked .
thanks very much .
need to sort browser now . i might be back
nclemale 03-02-2010, 09:20 PM can someone help me on how to use that code so that i can see errors etc .
never used it before.
angst 03-02-2010, 09:21 PM mysql_query() or Die(mysql_errno() . ": " . mysql_error());
|
|