Integrate this script into wordpress

Discussion in 'WordPress' started by snails07, May 26, 2011.

  1. #1
    Hi all, I have a PHP script that I would like to incorporate into my wordpress site. It is a golf handicap script.

    Basically I want a user to be able to log in and be able to edit and update their latest golf scores which will then update their handicap.
    So what I need to know is, how do I get this script to work in with the wordpress users and so that it will save their handicapping info.
    I can get around editing themes and plugins alright but this one is a bit beyond me.

    Any help is appreciated.

    You can check out the code for it here http://pastebin.com/5m7M79b3 (it's 2 files but I have pasted them both in the same one for ease of reading)
     
    snails07, May 26, 2011 IP
  2. friendlymentor

    friendlymentor Peon

    Messages:
    177
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Where exactly are you looking to display that information?
     
    friendlymentor, May 26, 2011 IP
  3. otjutt

    otjutt Member

    Messages:
    166
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #3
    What about editing the profile.php file and adding golf score field there? In this way users can login then go to their profile and update the golf score. The golf score field will then be displayed somewhere on your site as you like.
     
    otjutt, May 26, 2011 IP
  4. friendlymentor

    friendlymentor Peon

    Messages:
    177
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yup as said correctly by otjutt:

    If you just want to put an option where uers can input the information, just edit profile.php:

    <form action="your-golf-file.php" method="post">
    <create tables here according to what you want>
    </form>
     
    friendlymentor, May 26, 2011 IP
  5. snails07

    snails07 Member

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Thanks for the replies guys. This is exactly what I want to do, incorporate the handicap system into the users profile page.
    But is it really this easy? How exactly would I incorporate it so that the info is saved in the database? Would I use the wp_usermeta table?
    I’ve never really attempted anything like this so any ideas will be helpful.

    Thanks
     
    snails07, May 31, 2011 IP
  6. snails07

    snails07 Member

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    Okay so I have it mostly set up and working now. I can go to the page that I have inserted the script on and enter all of the information which is saved into the database just using its own table. The script is working, it is saving and retrieving all of the correct data but now the question is how to connect this script with the current logged in user.

    I'm guessing I have to somehow associate the script with the user id of the logged in user. Does that sound right?
    What would I need to change to do this? I'm thinking it is somewhere around this part of the script that I need to modify...

    
    // Get the user name if submitted.
    if($_POST['user']){
     $user=$_POST['user'];
     $gh->setuser($user);
    }
    if($_POST['delete']){          //delete the record
      $id=$_POST['id'];
      $gh->deleteGame($id);
    }
    if($_POST['edit']){           //edit the record
      $id=$_POST['id'];
    }
    // If no user yet, ask for it.
    if(!isset($_POST['user'])){
     print "<form name='usr' action='http://publicaccessgolf.com.au/handicap' method='POST'>";
     print "Enter your user name:<input type='text' name='user' size='20'>";
     print "<input type='hidden' name='hid' value='true'>";
     print "<input type='submit' value='Submit' name='submits'>";
     print "</form>";
    }else{
    // We have a username, so get new game data and display handicap and all games.
    print "<h2>Golf Game Database and Handicap Calculator for $user</h2>\n";
    $newgame=$gh->getnewgame($id);
    $id=($_POST['edit']=="")? "":$id;
    $gh->showform($id);
    $hc=$gh->gethcap();
    print ($hc==0)?"<h3>You need at least 5 games for a handicap index.</h3>":"<h3>Handicap for $user is $hc</h3><br>";
    // If you just want the data without displaying it, use next line.
    //$al=$gh->getAll();
    $gh->showall();
    PHP:


    and possibly this area of the second file...



    function setupdb($dbuser,$pw,$dbase)
    {
     $this->dbuser=$dbuser;
     $this->pw=$pw;
     $this->dbase=$dbase;
     $this->db = mysql_connect('localhost',$dbuser,$pw);
    }
    
    // Sets the player's name.
    function setuser($user)
    {
     $this->user=$user;
     return true;
    }
    
    // Retrieves the submitted new game information and stores it in the database.
    function getnewgame($id="")
    {
    if($_POST['submit']){
    // print "submit=".$_POST['submit'];
    // $id=$_POST['id'];
     $user=$_POST['user'];
     $this->user=$user;
     $date =$_POST['date1'];
    $d=explode("/",$date);
    $date=date("m/d/Y",mktime(0,0,0,$d[0],$d[1],$d[2]));
    PHP:

    Thanks again
     
    snails07, May 31, 2011 IP