Jump to content


Photo

Need help with php script..


  • Please log in to reply
2 replies to this topic

#1 waynem80

waynem80

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 22 July 2007 - 03:31 PM

Ok, so i'll explain the best i can Smiley .. I've found a free php script that uses a DB to store a golf players score and handicap... Problem is, the way the php script is written it doesn't even require the person to be a registered user. It just ask the person to enter a username "so they could make up one if they wanted" and then it uses the username they entered to store the scores in the DB under that name.

So here's my real problem...
I'm trying to integrate this with my website. I have a forum on my website powered by " Vanilla". I would like to setup this script so that only people that are members of the forum can use the script. AND the script will look to see if the user is logged in or not, and if they are, it will us there data as the username for the php script to store the scores etc.. in.

I'm sorry, but i dunno very much about php, anything i try to do right now with php takes hours and hours, i'm learning as much as possible, but i get stuck "with what ya'll would consider easy problems" all the time Undecided .

So if anyone could help point me in the right direction with what i'm trying to do i will be forever in debt. Grin

Below is the php script and the SQL that came with it.
First things first, i need to figure out the best place to put the SQL tables, since i'm trying to use the vanilla username db.


here's the SQL that came with it too.

CREATE TABLE `golfhcapu` (
`id` int(11) NOT NULL auto_increment,
`user` varchar(30) NOT NULL default '',
`course` varchar(50) default NULL,
`date` varchar(10) NOT NULL default '',
`score` int(11) NOT NULL default '0',
`crating` decimal(11,1) NOT NULL default '0.0',
`srating` int(11) default NULL,
`hcapdiff` decimal(11,1) NOT NULL default '0.0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=16 ;

There are 2 php files for this script, here they are below.
1. agolfhandicap.php
2. class.agolfhandicap.php



And here are the resources..

Demo of script as is.. http://www.gaclarke....p/handicapu.php
and where the script came from.. http://phpclasses.pr...ckage/2546.html

And here's my golf site I'm trying to integrate this with... http://www.ncgolfers.com


So, I guess I need to somehow take the current user session that vanilla is using and apply it to this script. That's about all that needs to be done i guess right?? :)

Thank you very much,
Wayne

Edited by waynem80, 22 July 2007 - 03:38 PM.


#2 waynem80

waynem80

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 22 July 2007 - 03:39 PM

I've included this code in all of the pages of my site that are outside of vanilla to check the user session and to state whether their logged in or not, and display if they are, and show a login/register button if they're not...

Here's that code, cause it might help out with my problem.. Posted Image

{$Context->Session->User->Name}.";
echo ' [url="http _linenums:0'>include("north-carolina/community/appg/settings.php"); //these are the files vanilla uses for sessions etc..include("north-carolina/community/appg/init_people.php"); //these are the files vanilla uses for sessions etc..if ($Context->Session->UserID){echo "Signed in as <strong class='bbc'>{$Context->Session->User->Name}</strong>.";echo ' [url="http://www.ncgolfers.com/north-carolina/community/people.php?PostBackAction=SignOutNow"]'.('[ Sign Out ]').'[/url]';}else{echo "Welcome, Guest.";echo ' [url="http://www.ncgolfers.com/north-carolina/community/people.php?ReturnUrl=http://www.ncgolfers.com/north-carolina/community/"]'.('[ Login').'[/url]';echo " or";echo ' [url="http://www.ncgolfers.com/north-carolina/community/people.php?PostBackAction=ApplyForm"]'.('Register ]').'[/url]';}?>


#3 Edmachine

Edmachine

    Young Padawan

  • Members
  • Pip
  • 44 posts
  • Gender:Male
  • Location:Latvia

Posted 23 July 2007 - 02:14 AM

I just woke up, maybe this won't work, don't know.

Here is how I do it on my site.

I add
<?php
session_start();
?>
at the start of each page.

Then, if the script I have allows me to enter any name I want, I do this.

I make a variable $username = $_SESSION['s_username'] (Your's should be different replace s_username with your... umm.. thing)

Where there are text fields for name, I delete them, where there are error for empty name fields, I delete them.

Uhh, where there are something like this $username = $_POST['name'] (or the name fields name)
I replace with the variable I mentioned earlier, then where the SQL query is for high scores, I change the variable to what I need (for example, INSERT INTO golf (name,score,something) VALUES ($username,$score,$something) and username is that variable.


Ok, I found it:

// Get the user name if submitted.
if($_POST['user']){
$user=$_POST['user'];
$gh->setuser($user);

change the variable to $_SESSION[yourusernamesessionname] (or what you usually have)

// If no user yet, ask for it.
if(!isset($_POST['user'])){
print "";
print "Enter your user name:";
print "";
print "";
print "";

I am not sure, but I think you can delete that...

On the second code...

if($_POST['submit']){
// print "submit=".$_POST['submit'];
// $id=$_POST['id'];
$user=$_POST['user'];

Change it again.

So, I think that is all... you should check for safety, if it doesn't work... well... don't know.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users