Hi,
If you see my other post about writing data to a file i am not doing that now i am using a database instead.
Anyway ....
Before i start i would like to say i am very very new to PHP and no very very little about MySQL writing.
Basically i have a dbconnect.php form, this will connect to a database then i have another form called visitrecorder.php
the visitrecorder.php collects data about user when visiting webpage ( i use
<?php include("visitorrecorder.php"); ?>
in my webpages i want to collect data for) and i want it to after it collects data for it to send to a database. Problem is i don't know how to write the SQL query to insert table into phpMyAdmin and if someone could look at this code and tell me am i doing it rite?
If you read the code you probably know what i am trying to do.
So this is what i want, i am not sure if i done it correctly i want to insert "$dbtime","$ip","$host","$agent","uri","$ref" into a database called visitordata.
Can someone tell me in my code have i done the insert to correctly? and if someone could create the table sql thingy as i dont have a clue. Learning PHP and MySQL at once is hard for me lol.
I am not sure if i also need an ID inserted, i mean everytime data is sent to database i dont want any data that is already there overwritten.
<?php
include("dbconnect.php");
$dtime = date('F jS Y, h:iA');
$ip = $_SERVER['REMOTE_ADDR'];
$host = gethostbyaddr($ip);
$agent = $_SERVER['HTTP_USER_AGENT'];
$uri = $_SERVER['REQUEST_URI'];
$ref = $_SERVER['HTTP_REFERER'];
if($dtime == ""){
$dtime = "None Recorded";
}
if($ip == ""){
$ip = "None Recorded";
}
if($host == ""){
$host = "None Recorded";
}
if($agent == ""){
$agent = "None Recorded";
}
if($uri == ""){
$uri = "None Recorded";
}
if($ref == ""){
$ref = "None Recorded";
}
"INSERT INTO visitordata () VALUES ("$dbtime","$ip","$host","$agent","uri","$ref")"; //*visitordata is the name of the MySQL table where the user data will be saved.
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "The user data was successfully added to your database.";
mysql_close($conn);
?>
Thank you,
genieuk