Jump to content

Creating a Member Database-- Using ifastnet.com


phake

Recommended Posts

Alright, I know HTML, CSS, and I'm a PHP beginner. I've tried creating a member database using ifastnet.com, but it seems to never work. When I say "member database", I mean just a basic member sigh up. Would anyone be willing to help me? Thanks!

Link to comment
Share on other sites

Here are my codes:

I used this code for connect.php:

 

<?php

 

// This script will connect the user to your mySQL database.

// It will also check it they're logged in or not.

// It should be included on every page you create.

 

// Set the variables below to match your settings

$dbhost = 'localhost';

$dbuser = 'root';

$dbpass = '';

$dbname = 'mygame';

 

$link = mysql_pconnect($dbhost, $dbuser, $dbpass)

or die("Could not connect to server.");

$selectdb = mysql_select_db($dbname, $link)

or die("Could not connect to database.");

 

// Check to see if user is logged in

 

session_start();

 

if((!isset($_SESSION['id'])) || (!isset($_SESSION['username'])) ||

(!isset($_SESSION['password'])))

{

unset($_SESSION['username']);

unset($_SESSION['password']);

unset($_SESSION['id']);

 

$loggedin = 0;

}

else

{

$loggedin = 1;

}

 

?>

 

 

This code for index.php:

 

<?php

 

include('connect.php');

 

if($loggedin == '0')

{

if(isset($_POST['submit']))

{

 

// Make sure all forms were filled out.

 

if((!isset($_POST['username'])) || (!isset($_POST['pass']))

|| ($_POST['username'] == '') || ($_POST['pass'] == ''))

die("Please fill out the form completely. <br><br>

<a href=index.php>Continue</a>");

 

// Get user's record from database

$player = @mysql_query("SELECT id, username, password, registered, lastlogin FROM players WHERE username = '".$_POST['username']."'");

$player = @mysql_fetch_assoc($player);

 

if($player['id'] == false)

die("Sorry, that user is not in our database.<br><br>

<a href=index.php>Back</a>");

else if($player['password'] != md5($_POST['pass']))

die("Wrong password!<br><br>

<a href=index.php>Back</a>");

 

// set session variables

$_SESSION['id'] = $player['id'];

$_SESSION['username'] = $player['username'];

$_SESSION['password'] = $player['password'];

 

// update last login

$date = date("m/d/y");

 

$update = @mysql_query("UPDATE players SET lastlogin = '$date' WHERE id = '".$_SESSION['id']."'");

 

echo 'You are now logged in!';

 

}

else

{

echo 'You are not logged in. <br><br>

<form action=index.php method=post>

Username: <input type=text name=username><br>

Password: <input type=password name=pass><br>

<input type=submit name=submit value=Submit>

</form>

Would you like to <a href=register.php>register?</a>';

}

}

else

{

echo 'You are logged in!

Welcome to my game, '.$_SESSION['username'].'!

<br><br>

<a href=logout.php>Click Here to Logout</a>';

 

}

 

?>

 

This code for register.php:

<?php

include('connect.php');

 

if($loggedin == '1')

die("You can't register another account while you're logged in.");

 

// Register Script

// So, the register script is a sample of the basic elements of

// coding used in a simple sim game, namely, putting new data

// into databases.

 

if(isset($_POST['submit']))

{

 

// trim removes the whitespaces from the beginning and end of text

// this keeps someone from having a username of " "

$uname = trim($_POST['username']);

 

// Make sure all forms were filled out.

 

if((!isset($_POST['username'])) || (!isset($_POST['pass']))

|| ($uname == '') || ($_POST['pass'] == ''))

die("Please fill out the form completely. <br><br>

<a href=register.php>Continue</a>");

 

// Make sure name hasn't already been used.

$check = @mysql_query("SELECT id FROM players WHERE username = '$uname'");

$check = @mysql_num_rows($check);

 

if($check > 0)

die("Sorry, that username has already been taken. Please try again.

<br><br>

<a href=register.php>Continue</a>");

 

// Encrypt password

$pass = md5($_POST['pass']);

 

$date = date("m/d/y");

 

// Finally, create the record.

$newPlayer = @mysql_query("INSERT INTO players (username, password, registered) VALUES ('$uname', '$pass', '$date')") or die("Error: ".mysql_error());

 

echo 'You have been registered! You may now <a href=index.php>Log in</a>.';

 

 

}

else

{

 

// A simple example of a form.

 

echo '<form action=register.php method=post>

Username: <input type=text name=username><br>

Password: <input type=password name=pass><br>

<input type=submit name=submit value=Submit>

</form>';

 

}

 

 

?>

 

This code for logout.php

 

<?php

 

include('connect.php');

 

unset($_SESSION['id']);

unset($_SESSION['username']);

unset($_SESSION['password']);

$_SESSION = array();

@session_destroy();

 

echo 'You have been logged out. <a href=index.php>Continue</a>';

 

?>

 

And this for the database:

 

 

username varchar 150

password varchar 150

registered varchar 15

lastlogin varchar 15

Link to comment
Share on other sites

I wouldnt use include (connect.php)

 

Perhpas it is better if you connected each time

 

And try not to use $ for name and passwords

 

Just put them directly in the code

 

$con = mysql_connect("localhost","name","password");

 

That would propably get rid of some hustle

Link to comment
Share on other sites

Okay, but wait, I don't believe my database has a password. So...

 

// Set the variables below to match your settings

$dbhost = 'localhost';

$dbuser = 'root';

$dbpass = '';

$dbname = 'mygame';

 

And if I took away connect.php, then I'd have to edit the pages that include connect.php, but then how does the script know how to connect?

 

(I'm sorry for all this, I'm such a PHP n00b, haha)

Link to comment
Share on other sites

It looks like you need to set your database settings in the connect.php file:

 

$dbhost = 'localhost';

$dbuser = 'root';

$dbpass = '';

$dbname = 'mygame';

 

You will need to obtain these settings from ifastnet.com.. The 'localhost' and 'mygame' settings are probably fine, but you definitely won't be able to connect as 'root', especially not without a password :)

 

 

Link to comment
Share on other sites

It looks like you need to set your database settings in the connect.php file:

 

$dbhost = 'localhost';

$dbuser = 'root';

$dbpass = '';

$dbname = 'mygame';

 

You will need to obtain these settings from ifastnet.com.. The 'localhost' and 'mygame' settings are probably fine, but you definitely won't be able to connect as 'root', especially not without a password :)

 

 

 

Sometimes localhost won't even work. On my site I have to use sql3.mysql or something similar to that. Make sure you find the correct connecting information.

Link to comment
Share on other sites

thats weired to me, cus i alwasy dealt with database that needs password

Well, the error says you need password

So, there must be something you need to put

Or perhaps, just leave it empty

and get rid of $ i think, and put details straight away

or use print"$dbuser" to see a little on whats going on

you know, keep trying

Cus sometimes, i know the connection to databse can get really tricky (and it is simple)

Link to comment
Share on other sites

Well, I found my server, put that in, and now it shows:

 

Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'sq12.ifastnet.co'@'localhost' (using password: NO) in /home/damianlayouts/connect.php on line 21

 

Should I switch hosts? If I did, the other'd have to be free, as I have no serious plans as of yet, I mean, I'm just a beginner.

Link to comment
Share on other sites

I don't know the pass, but here's the code in connect.php:

 

<?php

 

// This script will connect the user to your mySQL database.

// It will also check it they're logged in or not.

// It should be included on every page you create.

 

// Set the variables below to match your settings

$dbhost = 'localhost';

$dbuser = 'sq12.ifastnet.com';

$dbpass = '';

$dbname = 'mygame';

 

$link = mysql_pconnect($dbhost, $dbuser, $dbpass)

or die("Could not connect to server.");

$selectdb = mysql_select_db($dbname, $link)

or die("Could not connect to database.");

 

// Check to see if user is logged in

 

session_start();

 

if((!isset($_SESSION['id'])) || (!isset($_SESSION['username'])) ||

(!isset($_SESSION['password'])))

{

unset($_SESSION['username']);

unset($_SESSION['password']);

unset($_SESSION['id']);

 

$loggedin = 0;

}

else

{

$loggedin = 1;

}

 

?>

Link to comment
Share on other sites

Ummm the code is correct (I'm assuming).

 

The problem is that it cannot connect to the mysql server do to the mysql server rejecting the username and/or password.....  Find out that stuff from your host and build the DB and you should be good to go.

Link to comment
Share on other sites

Well, you definitely need to figure out your mySQL username and password, otherwise you will never connect successfully.. You should search the ifastnet.com support documents for help or try to contact them if possible.. Be sure to check your signup e-mail that they should have sent you, it might have the info in there..

 

But, it looks like you put your host name in the user variable, you should probably be setting it like this:

 

$dbhost = 'sq12.ifastnet.com';

$dbuser = 'USERNAME';

$dbpass = 'PASSWORD';

$dbname = 'mygame';

 

Link to comment
Share on other sites

Now it's saying it can't connect and the problem is at:

 

unset($_SESSION['id']);

 

 

 

UGH!

 

that's not where the problem is. it may tell you that's where it is, but you have to do a little more searching. it's probably very close. you should post that line, and 5 lines before it, and 5 lines after it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.