Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default PHP Database Script [+REP]

    I have a database with 3 rows: Name, x-cord, y-cord. I need a script to handle all of these.

    • My external application sends the Name, x-cord and y-cord to the PHP file via POST
    • The PHP file saves Name, x-cord and y-cord to the database, overwriting the current x-cord and y-cord that goes with Name.
    • Once the x-cord and y-cord are saved into the Database they need to be written into name.txt, again overwriting anything in there.
    For example:
    Name = John
    x-cord = 2
    y-cord = 4

    So John, 2 and 4 are saved in the database columns Name, x-cord and y-cord respectively. Once saved into the database x-cord and y-cord are written out into John.txt. John.txt then looks like
    x-cord = 2
    y-cord = 2
    If anyone could do this fairly easy task then I will love you for eternity and give you +REP too.

  2. #2
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Anyone??? I really really need this.

    Edited by Johno! (Forum Moderator): Please do not multiple post, thanks!
    Last edited by Johno; 23-06-2009 at 06:12 PM.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,365
    Tokens
    250

    Latest Awards:

    Default

    Sheez, what is Georgie Porgie working on now!?
    Nexdana.com - FREE ONLINE GAMES & FORUM COMMUNITY!

  4. #4
    Join Date
    May 2007
    Posts
    10,481
    Tokens
    3,140

    Latest Awards:

    Default

    I'll try and whip up something that'll send it to the DB and then I will mash together something that will send it to the file, however I am going out soon so don't expect it till tomorrow :/

    Edit: I am going to do it from a modified register file from tech tut's Naresh Usersystem, you could try yourself and learn something...

    Edit2: Are the details going to be from a form? If so then you may need to secure it a bit...


    Only does DB for now... Havn't tested it either, should work though as I modified an existing script of mine...
    PHP Code:
    <?php
       $conn 
    mysql_connect("localhost","[Username]","[Password]");
       
    mysql_select_db([DB_Name]) or die(mysql_error());
       
    //fill in the above lines where there are capital letters.
    $name $_POST[name];
    $xpos $_POST[x];
    $ypos $_POST[y];

    $query mysql_query("INSERT INTO [Table Name] (name, x, y) VALUES('$name','$xpos','$ypos')");
    echo(
    '[Message to Echo upon completion]')
    ?>
    Last edited by Chippiewill; 23-06-2009 at 04:47 PM.
    Chippiewill.


  5. #5
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by 00chips View Post
    I'll try and whip up something that'll send it to the DB and then I will mash together something that will send it to the file, however I am going out soon so don't expect it till tomorrow :/
    Ok thanks! I literally love you lol. If you ever need anything done then just ask.

    Quote Originally Posted by 00chips View Post
    Edit: I am going to do it from a modified register file from tech tut's Naresh Usersystem, you could try yourself and learn something..
    The thing is, I rarely use PHP so there isnt really much point me learning it. Atleast not at this current time.


    Quote Originally Posted by 00chips View Post
    Edit2: Are the details going to be from a form? If so then you may need to secure it a bit...
    All of that can be handled by me. I dont need a form created or anything, it will simply be sent to the PHP file via POST.

  6. #6
    Join Date
    May 2007
    Posts
    10,481
    Tokens
    3,140

    Latest Awards:

    Default

    Ok basically finished it, the syntax may be wrong so someone may want to quickly check it

    PHP Code:
    <?php
       $conn 
    mysql_connect("localhost","[Username]","[Password]");
       
    mysql_select_db([DB_Name]) or die(mysql_error());
       
    //fill in the above lines where there are capital letters.
    $name $_POST[name];
    $xpos $_POST[x];
    $ypos $_POST[y];
    $query mysql_query("INSERT INTO [Table Name] (name, x, y) VALUES('$name','$xpos','$ypos')");


    $myFile $name'.txt';
    $fh fopen($myFile'w') or die("can't open file");
    $stringData 'x-cord = ' $xpos \n;
    fwrite($fh$stringData);
    $stringData 'y-cord = ' $ypos \n;
    fwrite($fh$stringData);
    fclose($fh);

    echo(
    '[Message to Echo upon completion]')

    ?>
    Also by form I meant, is the end user going to specify this information, if so then it needs to be secured so that people can't use JS injections e.t.c.
    Last edited by Chippiewill; 23-06-2009 at 04:57 PM.
    Chippiewill.


  7. #7
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Whoa, thanks! Very speedy! Does that overwrite whats in the database if it already exists? Oh and replace whats in the textfile?

  8. #8
    Join Date
    May 2007
    Posts
    10,481
    Tokens
    3,140

    Latest Awards:

    Default

    Erm, for the DB you need to use IDs to overwrite it I think, not to sure. I will have a quick think about it.

    Edit: I think if I get it to delete the existing row then it'll work...

    Edit2: Try this....

    PHP Code:
     <?php
       $conn 
    mysql_connect("localhost","[Username]","[Password]");
       
    mysql_select_db([DB_Name]) or die(mysql_error());
       
    //fill in the above lines where there are capital letters.
    $name $_POST[name];
    $xpos $_POST[x];
    $ypos $_POST[y];
    mysql_query("DELETE FROM [Table Name] WHERE name='$name'")  
    $query mysql_query("INSERT INTO [Table Name] (name, x, y) VALUES('$name','$xpos','$ypos')");


    $myFile $name'.txt';
    $fh fopen($myFile'w') or die("can't open file");
    $stringData 'x-cord = ' $xpos n;
    fwrite($fh$stringData);
    $stringData 'y-cord = ' $ypos n;
    fwrite($fh$stringData);
    fclose($fh);

    echo(
    '[Message to Echo upon completion]')

    ?>
    Last edited by Chippiewill; 23-06-2009 at 05:22 PM.
    Chippiewill.


  9. #9
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    90

    Latest Awards:

    Default

    Just use UPDATE in MySQL.

  10. #10
    Join Date
    Dec 2007
    Posts
    2,807
    Tokens
    0

    Latest Awards:

    Default

    Thanks for all the help 00Chips, like I said, if you ever need anything then just PM me.

    Quote Originally Posted by Robbie! View Post
    Just use UPDATE in MySQL.
    How exactly would you use that in the context of this?

    One final question while I'm here for something else I'm working on, how would I edit the last bit of code so it doesn't write over whats in the text file and just adds it to the bottom?

Page 1 of 2 12 LastLast

Posting Permissions

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