Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-02-2004, 02:17 AM   PM User | #1
colabus
New to the CF scene

 
Join Date: Jun 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
colabus is an unknown quantity at this point
php/MySQL request.

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,
Code:
<?
$username=username;
$password=password;
$database=ipLOG;
mysql_connect(localhost,$username,$password);
@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

mysql_close();
?>
if anyone could help, it would be great.
thanks
colabus is offline   Reply With Quote
Old 06-02-2004, 09:18 PM   PM User | #2
MrShed
New Coder

 
Join Date: Jun 2004
Location: Newcastle, England
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
MrShed is an unknown quantity at this point
well are you actually having any problems with it so far? is there like a specific question you want answered or just general help?
MrShed is offline   Reply With Quote
Old 06-03-2004, 05:50 AM   PM User | #3
colabus
New to the CF scene

 
Join Date: Jun 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
colabus is an unknown quantity at this point
I ended up working out the problem.

Seems tables can't start with a numbers or have dashes in their names
colabus is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:18 AM.


Advertisement
Log in to turn off these ads.