View Full Version : php/MySQL request.

06-02-2004, 03:17 AM
I'm sort of new to these languages, I have been doing php for a couple of weeks and finally got an idea how to use MySQL just 2 days ago. Anyhow I'm building a script that reads a file (line-by-line), sets 4 variables ($date, $ip, $time and $name) and I want to build them into a database. Something like:

Database: ipLOG
Table: $date, then 3 columns ($time, $name and $ip)

It's actually storing iplogs from a game server I run.
Well I got the vars set and can loops through the file fine, it's just the mysql side. I need to 1. check the the table ($date) exists, and if not make it, 2. then check if there's any matches for $ip, $name, $time and if not put them into the database (so it doesn't put duplicates in).

here's what I have (mysql wise) so far,

@mysql_select_db($database) or die("Database failure.."); //this is all fine

//now the loop starts (I didn't paste that tho)

$query = "CREATE IF NOT EXISTS TABLE $date (
time varchar(5) NOT NULL,
name varchar(20) NOT NULL,
ip varchar(15) NOT NULL

mysql_query($query); //if no table, build it

$query="SELECT * FROM $date WHERE time='$time' AND name='$name' AND ip='$ip'";

$result=mysql_query($query); // check if there's a row with the set info (so no duplicates)

$num=mysql_numrows($result); //sets num, assuming there is a match $num will exist.

if (!$num) {
$query="INSERT INTO $date VALUES ('','$time','$name','$ip')";
mysql_query($query); //if $num didn't exist, write the info

//loop ends


if anyone could help, it would be great.

06-02-2004, 10:18 PM
well are you actually having any problems with it so far? is there like a specific question you want answered or just general help?

06-03-2004, 06:50 AM
I ended up working out the problem.

Seems tables can't start with a numbers or have dashes in their names