Jump to content

What wrong with this code?


Flowdy

Recommended Posts

I seem to keep getting problems with this code

 

<?php

// This script will connect user to the database.
// It will also check if logged in or not.
// It should be included on every page created.

// Set the variables below to match your settings
$dbhost = 'localhost';
$dbuser = 'flow';
$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 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;
}

?>

 

The error i get is

Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'flow'@'localhost' (using password: YES) in /home/poison/public_html/testphp/connect.php on line 13

Could not connect to server.

 

thanx

Link to comment
Share on other sites

I changed the die() and this is the error i got

 

Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'flow'@'localhost' (using password: YES) in /home/poison/public_html/testphp/connect.php on line 13
Could not connect to server.Access denied for user 'flow'@'localhost' (using password: YES)

 

I asked about the username earlier today and i got a reply saying i should use the username i assigned to the database

Link to comment
Share on other sites

this isnt the problem, but just some advice.

I would not recommend mysql_pconnect().

because this will produce a permenant connection, and for this

to work correctly. you will need to configure apache, so you dont

exceed your maximum connections. etc.

 

This could cause the server to fail.

Link to comment
Share on other sites

I asked about the username earlier today and i got a reply saying i should use the username i assigned to the database

 

Yes, that is what you are supposed to use in the mysql_connect() function. We all assumed that the posted information was what this was.

 

When you create a database, you also created a user and a password for that user. The database user and his password are what you use in the mysql_connect() function call.

Link to comment
Share on other sites

Thanx guys i got it working thanx to your help...i changed the connection to mysql_connect()

 

but now i have a different problem :(

on the register.php

 

<?php
include('connect.php);

if($loggedin == '1')
die("you can't register another account while you're logged in.");

// Register Script
// 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 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 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 make 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>';

}

?>

 

The error i get is

Parse error: syntax error, unexpected T_LNUMBER in /home/poison/public_html/testphp/register.php on line 4
Link to comment
Share on other sites

Yeah it must be on the connect.php as the other are ...index.php...logout.php and register.php and they all coming up with the cannot connect to database.

 

PHP is confusing dont think ill ever get to understand 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.