Flowdy Posted November 28, 2007 Author Share Posted November 28, 2007 in the MySQL databases via Control Panel there is nothing under the database i made for this code ??? just has the title poison_mygame Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401006 Share on other sites More sharing options...
~n[EO]n~ Posted November 28, 2007 Share Posted November 28, 2007 If you are using cPanel, when you log in do you see various icons (see attached pic), then when you click on MySQL Database you will see the connection string at the top (under MySQL Account Maintenance) like this Connection Strings Perl $dbh = DBI->connect("DBI:mysql:ad_joke:localhost","ad_joker","<PASSWORD HERE>"); PHP $dbh=mysql_connect ("localhost", "ad_joker", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("ad_joke"); Note ; password is not shown there , if you forgot the password you can delete current user and create a new one. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401010 Share on other sites More sharing options...
Flowdy Posted November 28, 2007 Author Share Posted November 28, 2007 I did that and this is what i see [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401014 Share on other sites More sharing options...
~n[EO]n~ Posted November 28, 2007 Share Posted November 28, 2007 Now your connection must be like this, please keep the password and try <?php $dbhost = "localhost"; $dbuser = "poison_frgn1"; $dbpass = " "; // keep your password here $dbname = "poison_frgn1"; $link = mysql_connect($dbhost, $dbuser, $dbpass); if (!$link) { die('Could not connect: ' . mysql_error()); } $selectdb = mysql_select_db($dbname) or die("Could not connect to database."); ?> Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401018 Share on other sites More sharing options...
Flowdy Posted November 28, 2007 Author Share Posted November 28, 2007 The posion_frgn1 isnt the database i made for this its the poison_game one is the first attached image... so i put in the poison_game instead, this being the new code <?php $dbhost = "localhost"; $dbuser = "poison_mygame"; $dbpass = ""; // keep your password here $dbname = "poison_mygame"; $link = mysql_connect($dbhost, $dbuser, $dbpass); if (!$link) { die('Could not connect: ' . mysql_error()); } $selectdb = mysql_select_db($dbname) 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; } ?> I took my password out but now i get this message ??? Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'poison_mygame'@'localhost' (using password: YES) in /home/poison/public_html/testphp/connect.php on line 7 Could not connect: Access denied for user 'poison_mygame'@'localhost' (using password: YES) Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401025 Share on other sites More sharing options...
~n[EO]n~ Posted November 28, 2007 Share Posted November 28, 2007 You have 2 database, keep the correct database and password. Seeing your attached pic there are 2 db named poison_mygame AND poison_wrdp1 First be sure which you are using, and keep the connection string accordingly, You must keep the password too... Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401027 Share on other sites More sharing options...
helraizer Posted November 28, 2007 Share Posted November 28, 2007 n~ link=topic=169493.msg748629#msg748629 date=1196244152] Now your connection must be like this, please keep the password and try <?php $dbhost = "localhost"; $dbuser = "poison_frgn1"; $dbpass = " "; // keep your password here $dbname = "poison_frgn1"; $link = mysql_connect($dbhost, $dbuser, $dbpass); if (!$link) { die('Could not connect: ' . mysql_error()); } $selectdb = mysql_select_db($dbname) or die("Could not connect to database."); ?> Why do you need $link? Not just: <?php mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect: ' . mysql_error()); ?> To me it looks tidier, but I'm no professional; just opinion. Also, just to eliminate any type of spelling error (even though there is none), have <?php $dbhost = "127.0.0.1"; ?> in the MySQL databases via Control Panel there is nothing under the database i made for this code just has the title poison_mygame That could explain why you can't connect to the database - it doesn't exist. The posion_frgn1 isnt the database i made for this its the poison_game one is the first attached image... so i put in the poison_game instead, this being the new code <?php $dbhost = "localhost"; $dbuser = "poison_mygame"; $dbpass = ""; // keep your password here $dbname = "poison_mygame"; $link = mysql_connect($dbhost, $dbuser, $dbpass); if (!$link) { die('Could not connect: ' . mysql_error()); } $selectdb = mysql_select_db($dbname) 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; } ?> I took my password out but now i get this message Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'poison_mygame'@'localhost' (using password: YES) in /home/poison/public_html/testphp/connect.php on line 7 Could not connect: Access denied for user 'poison_mygame'@'localhost' (using password: YES) If you only get that error, it's now because you didn't use a password. Try the same code (with the changes I suggested above) but actually include your db password. Then in theory it should work. Sam Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401031 Share on other sites More sharing options...
Flowdy Posted November 28, 2007 Author Share Posted November 28, 2007 I did use my password last time i just took it out when posting the code on here....I changed things and now i get this the code <?php $dbhost = "localhost"; $dbuser = "poison_mygame"; $dbpass = ""; // keep your password here $dbname = "poison_mygame"; <?php mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect: ' . mysql_error()); ?> // 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 Parse error: syntax error, unexpected '<' in /home/poison/public_html/testphp/connect.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401036 Share on other sites More sharing options...
helraizer Posted November 28, 2007 Share Posted November 28, 2007 I did use my password last time i just took it out when posting the code on here....I changed things and now i get this the code <?php $dbhost = "localhost"; $dbuser = "poison_mygame"; $dbpass = ""; // keep your password here $dbname = "poison_mygame"; <?php mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect: ' . mysql_error()); ?> // 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 Parse error: syntax error, unexpected '<' in /home/poison/public_html/testphp/connect.php on line 7 You already have the <?php tag open at the top of the page.. you can't open it twice. Remove that tag and it should work. Sam N.B. I only put the <php tags on every piece of code I post here just so the php highlighting works. Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401038 Share on other sites More sharing options...
Flowdy Posted November 28, 2007 Author Share Posted November 28, 2007 Nope didnt work.. Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'poison_mygame'@'localhost' (using password: YES) in /home/poison/public_html/testphp/connect.php on line 8 Could not connect: Access denied for user 'poison_mygame'@'localhost' (using password: YES) Am starting to think i added a username and password to the database the wrong way Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401040 Share on other sites More sharing options...
helraizer Posted November 28, 2007 Share Posted November 28, 2007 Nope didnt work.. Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'poison_mygame'@'localhost' (using password: YES) in /home/poison/public_html/testphp/connect.php on line 8 Could not connect: Access denied for user 'poison_mygame'@'localhost' (using password: YES) Am starting to think i added a username and password to the database the wrong way Try omitting the variables and just type the values in as themselves (not sure why it'd work but it might). For example: <?php mysql_connect("127.0.0.1", "poison_mygame", "[your-password]"); // 127.0.0.1 goes to the IP of the host (where most likely your db is stored). mysql_select_db("poison_mygame"); ?> Sam Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401043 Share on other sites More sharing options...
Flowdy Posted November 28, 2007 Author Share Posted November 28, 2007 ooo that helped but now there are loads of errors you should be to see wat i mean by clicking here http://www.testphp.poison-envy.net/index.php Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401045 Share on other sites More sharing options...
Flowdy Posted November 28, 2007 Author Share Posted November 28, 2007 Sorry for the double post...incase you cant see the page as a friend told me she couldn't i get these errors Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'poison_mygame'@'localhost' (using password: YES) in /home/poison/public_html/testphp/connect.php on line 8 Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/poison/public_html/testphp/connect.php on line 9 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/poison/public_html/testphp/connect.php on line 9 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/poison/public_html/testphp/connect.php: in /home/poison/public_html/testphp/connect.php on line 14 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/poison/public_html/testphp/connect.php: in /home/poison/public_html/testphp/connect.php on line 14 But i can see text boxes for username password and submit button Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401120 Share on other sites More sharing options...
helraizer Posted November 28, 2007 Share Posted November 28, 2007 Could you post your code that you have now? The errors I saw on the page related to row 13, 14, 14, 18 and 18; so I'm assuming you've added some 4 lines of code somewhere above where they were before. Post your code and I'll see what I can do. Sam Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401145 Share on other sites More sharing options...
Flowdy Posted November 28, 2007 Author Share Posted November 28, 2007 Sure here is the code <?php $dbhost = "localhost"; $dbuser = "poison_mygame"; $dbpass = "england"; // keep your password here $dbname = "poison_mygame"; mysql_connect("127.0.0.1", "poison_mygame", "[england]"); // 127.0.0.1 goes to the IP of the host (where most likely your db is stored). mysql_select_db("poison_mygame"); // 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-401383 Share on other sites More sharing options...
helraizer Posted November 29, 2007 Share Posted November 29, 2007 Sure here is the code <?php $dbhost = "localhost"; $dbuser = "poison_mygame"; $dbpass = "england"; // keep your password here $dbname = "poison_mygame"; mysql_connect("127.0.0.1", "poison_mygame", "[england]"); // 127.0.0.1 goes to the IP of the host (where most likely your db is stored). mysql_select_db("poison_mygame"); // 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; } ?> Ok, I think that's my fault, take the square brackets out from your password in the mysql_connect() see if that works. I only put them there to say that's where to type your password, my bad. So if you have it as mysql_connect("127.0.0.1", "poison_mygame", "england"); That should work now. Sam Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-402008 Share on other sites More sharing options...
janim Posted November 29, 2007 Share Posted November 29, 2007 is it worked like what helraizer said mysql_connect("127.0.0.1", "poison_mygame", "england"); if not what is the server that you r using ? and you define $loggedin=1 then you are trying to use $if( $loggedin=='1' and that's defer be carful Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-402021 Share on other sites More sharing options...
Flowdy Posted November 29, 2007 Author Share Posted November 29, 2007 I took the brackets out and still not working...i dont quite understand what you mean janim Errors Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'poison_mygame'@'localhost' (using password: YES) in /home/poison/public_html/testphp/connect.php on line 8 Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/poison/public_html/testphp/connect.php on line 9 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/poison/public_html/testphp/connect.php on line 9 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/poison/public_html/testphp/connect.php: in /home/poison/public_html/testphp/connect.php on line 14 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/poison/public_html/testphp/connect.php: in /home/poison/public_html/testphp/connect.php on line 14 Code <?php $dbhost = "localhost"; $dbuser = "poison_mygame"; $dbpass = "england"; // keep your password here $dbname = "poison_mygame"; mysql_connect("127.0.0.1", "poison_mygame", "england"); // 127.0.0.1 goes to the IP of the host (where most likely your db is stored). mysql_select_db("poison_mygame"); // 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-402320 Share on other sites More sharing options...
helraizer Posted November 29, 2007 Share Posted November 29, 2007 I took the brackets out and still not working...i dont quite understand what you mean janim Errors Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'poison_mygame'@'localhost' (using password: YES) in /home/poison/public_html/testphp/connect.php on line 8 Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/poison/public_html/testphp/connect.php on line 9 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/poison/public_html/testphp/connect.php on line 9 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/poison/public_html/testphp/connect.php: in /home/poison/public_html/testphp/connect.php on line 14 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/poison/public_html/testphp/connect.php: in /home/poison/public_html/testphp/connect.php on line 14 Code <?php $dbhost = "localhost"; $dbuser = "poison_mygame"; $dbpass = "england"; // keep your password here $dbname = "poison_mygame"; mysql_connect("127.0.0.1", "poison_mygame", "england"); // 127.0.0.1 goes to the IP of the host (where most likely your db is stored). mysql_select_db("poison_mygame"); // 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; } ?> use { $loggedin == 0; } else { $loggedin == 1; } Is what I think he meant. session_start(); must be at the top of all your code. It would seem that your database isn't on the same server as your actual localhost. Unless.. are you using apache or a web server? Sam Quote Link to comment https://forums.phpfreaks.com/topic/79118-what-wrong-with-this-code/page/2/#findComment-402409 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.