Flowdy Posted November 27, 2007 Share Posted November 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/ Share on other sites More sharing options...
revraz Posted November 27, 2007 Share Posted November 27, 2007 Is the dbpass supposed to be empty? Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400431 Share on other sites More sharing options...
pocobueno1388 Posted November 27, 2007 Share Posted November 27, 2007 Looks like you have the wrong username or host. You might want to check in with your host to see if you are supposed to use "localhost". Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400433 Share on other sites More sharing options...
Flowdy Posted November 27, 2007 Author Share Posted November 27, 2007 I just took my password out.. My server is set for localhost i've set other things up and used the localhost before. Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400440 Share on other sites More sharing options...
revraz Posted November 27, 2007 Share Posted November 27, 2007 Does it allow persistant connections? Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400441 Share on other sites More sharing options...
Flowdy Posted November 27, 2007 Author Share Posted November 27, 2007 I havent got a clue what you mean ive only really new to PHP ??? The other thing i could think off with my username is that it should be poison_flow but then i get the same error message Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400443 Share on other sites More sharing options...
PFMaBiSmAd Posted November 27, 2007 Share Posted November 27, 2007 Change your or die() statement to see if mysql will give you more information about what the problem is - or die("Could not connect to server." . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400445 Share on other sites More sharing options...
revraz Posted November 27, 2007 Share Posted November 27, 2007 Can try mysql_connect instead of mysql_pconnect, but it looks like the wrong username/pw Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400448 Share on other sites More sharing options...
janim Posted November 27, 2007 Share Posted November 27, 2007 which server u use for i think most of servers uses " root " as username u are using flower it depends at the server that u use for php Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400450 Share on other sites More sharing options...
Flowdy Posted November 27, 2007 Author Share Posted November 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400455 Share on other sites More sharing options...
alecks Posted November 27, 2007 Share Posted November 27, 2007 btw how did you install mysql, what is your server's set up? try just using 'root' as your username and nothing for your password Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400502 Share on other sites More sharing options...
xyn Posted November 27, 2007 Share Posted November 27, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400504 Share on other sites More sharing options...
PFMaBiSmAd Posted November 27, 2007 Share Posted November 27, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400509 Share on other sites More sharing options...
Flowdy Posted November 27, 2007 Author Share Posted November 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400531 Share on other sites More sharing options...
pocobueno1388 Posted November 27, 2007 Share Posted November 27, 2007 Change include('connect.php); To include('connect.php'); Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400533 Share on other sites More sharing options...
Flowdy Posted November 27, 2007 Author Share Posted November 27, 2007 Ah thanx i feel stupid now am i just stupid cos when i go to http://www.testphp.poison-envy.net/register.php i just get Could not connect to database. shouldnt a form come up to register? Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400535 Share on other sites More sharing options...
pocobueno1388 Posted November 27, 2007 Share Posted November 27, 2007 Well...you need to figure out where that error is coming from to figure out whats wrong. I assume it's coming from your connection script...so something still must be wrong. Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400540 Share on other sites More sharing options...
Flowdy Posted November 27, 2007 Author Share Posted November 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400552 Share on other sites More sharing options...
revraz Posted November 27, 2007 Share Posted November 27, 2007 If it's a connection problem, the it's not PHP that's giving you a hard time, it's MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400554 Share on other sites More sharing options...
Flowdy Posted November 27, 2007 Author Share Posted November 27, 2007 Ah right ok! then i have no idea i really am that new to php/MySQL Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400558 Share on other sites More sharing options...
hamza Posted November 28, 2007 Share Posted November 28, 2007 There is nothing wrong with your code . server password is not correct .(simply) Correct your sever password it is not allowing you to access. thats it . Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400930 Share on other sites More sharing options...
Flowdy Posted November 28, 2007 Author Share Posted November 28, 2007 There is nothing wrong with your code . server password is not correct .(simply) Correct your sever password it is not allowing you to access. thats it . were do i correct it? in the code or somewere else? Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400985 Share on other sites More sharing options...
phpQuestioner Posted November 28, 2007 Share Posted November 28, 2007 in your script; it would be this variable: <?php $dbpass = ''; ?> Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400988 Share on other sites More sharing options...
Flowdy Posted November 28, 2007 Author Share Posted November 28, 2007 Ok thanx but i don't understand which password to put there as i thought it was the password for the username i added for the database? or would it be the password i use to login to my Cpanel? Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-400992 Share on other sites More sharing options...
~n[EO]n~ Posted November 28, 2007 Share Posted November 28, 2007 It is MySQL username and password not your ftp (cpanel login) password. If you have access to Cpanel then you can view the connection string by clicking MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/#findComment-401001 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.