Forum Moderators: coopster

Message Too Old, No Replies

Storing ip and time in variable

Storing ip and time in variable

         

kkonline

4:49 pm on Aug 14, 2007 (gmt 0)

10+ Year Member



In this code i want to store ip, time, month and year in $ip, $time, $month
and $year respectively.


<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("mysql", $con);

[b]
$time=strtotime("now");
$ip=<?php echo $_SERVER['REMOTE_ADDR'];?>
$month=<?php echo date("n", $date);?>
[/b]

$sql="INSERT INTO phpnews_news (ip, time, month, year, subject, titletext, maintext, views, break, catid, trusted)
VALUES
('$_POST[ip]','$_POST[time]','$_POST[month]','$_POST[year]','$_POST[subject]','$_POST[titletext]','$_POST[maintext]','0','0','$_POST[catid]','0')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}

echo "Article added on ";
echo date('l dS F Y h:i:s A');
echo " from ";
echo $_SERVER['REMOTE_ADDR'];

mysql_close($con)
?>

what is the proper way or syntax to write the above code in bold.

snowman304

5:14 pm on Aug 14, 2007 (gmt 0)

10+ Year Member



Here is how I do IPs:
$ip = $_SERVER[REMOTE_ADDR];
$ip = long2ip(ip2long($ip));

For $time, if you are wanting the current time stamp, do it in sql. EX:

$query = "INSERT INTO members (fname, mi, lname, suffix, gender, address, city, state, zipcode, phone, ip, time)
VALUES ( '$fname', '$mi', '$lname', '$suffix', '$gender', '$address', '$city', '$state', '$zipcode', '$phone', '$ip', now() )";