Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Thanked 0 Times in 0 Posts

    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,
    @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.

  2. #2
    New Coder
    Join Date
    Jun 2004
    Newcastle, England
    Thanked 0 Times in 0 Posts
    well are you actually having any problems with it so far? is there like a specific question you want answered or just general help?

  3. #3
    New to the CF scene
    Join Date
    Jun 2004
    Thanked 0 Times in 0 Posts
    I ended up working out the problem.

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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts