I’m able to store an IP address in the database using the INET_ATON function but I’m having trouble converting it back the other way with INET_NTOA.
My SQL statement is as follows..
$sql="SELECT `subnet_id`, INET_NTOA(`address`), `default_gateway`, `notes`, `site_id`, `user_id`, `mask_id` FROM `subnets`";
..which works when inputted directly into phpMyAdmin.
However when trying to echo the address row using the below two methods i’m getting the corresponding errors:
<td class="viewDataWidth"><?php echo INET_NTOA($rows['address']); ?></td>
Fatal error: Call to undefined function INET_NTOA() in
<td class="viewDataWidth"><?php echo $rows['INET_ntoa(address)']; ?></td>
Notice: Undefined index: INET_ntoa(address)
I can echo the address row (without the translation) but I assume I’m not using the INET_NTOA function correctly. I’ve messed around with it a little using trial and error and can’t seem to get anywhere.
Does anyone have any ideas?
Thanks
change your sql to use an alias, eg:
and then you should be able to fetch the field using
your first attempt didn’t work since you tried to call a php function “INET_NTOA” instead of retrieving the result from the mysql function. you could do that, but in php this function is called ‘ip2long’