Cless Posted July 12, 2007 Share Posted July 12, 2007 Hello, I recently created a Login script, however, as usual... An error with mysql_fetch_array and select. Heh. Does anyone know why this will not work? <?PHP //Begin Session session_start(); //Check If user Is Logged In if (isset($_SESSION['Username'])) { //Include Top File include("top2.html"); //Include Configuration File include("config.php"); //Set $Username $Username= $_SESSION['Username']; //Display Welcome Message echo "Hello, $Username. You are already logged in, sorry."; //Include Bottom File include("bottom2.html"); } else { //Include Top File include("top.html"); //Find Variables $Lo_Submit= $_POST['Lo_Submit']; $Lo_Username= $_POST['Lo_Username']; $Lo_Password= $_POST['Lo_Password']; $Lo_IP= $_SERVER['REMOTE_ADDR']; //Include Submit Function include("submit.html"); ?> <html> <hr> <b>-Logging In-</b><br> <hr> <small>The area of which you may login to The Pokémon Moon RPG.</small><br><br> </html> <?PHP //Check If Form Is Submitted if(!$Lo_Submit) { ?> <html> <form action="<?PHP $_SERVER['PHP_SELF']; ?>" method="POST"> <p class="center"><b>Username</b><br> <input type="text" name="Lo_Username" class="BasicInput" /></p> <p class="center"><b>Password</b><br> <input type="password" name="Lo_Password" class="BasicInput" /></p> <input type="submit" id="sbt_btn" name="Lo_Submit" type= "BasicInput" value="Login" onclick="hide_btn(this);" /> <span id="submit_btn_msg" style="display:none">Logging In...</span> </form> </html> <?PHP } else { //Check If Username Is Empty if(empty($Lo_Username)) { echo "You have left the Username field blank. Please <a href='/login.php'>Go Back</a>."; include("bottom.html"); exit; } elseif(empty($Lo_Password)) { echo "You have left the Password field blank. Please <a href='/login.php'>Go Back</a>."; include("bottom.html"); exit; } else { $Result1= mysql_query("SELECT * FROM Users WHERE Username='$Lo_Username'"); $Rows1= mysql_fetch_array($Result1); if(empty($Rows1)) { echo "Sorry, that User does not exist. Please <a href='/login.php'>Go Back</a>."; include("bottom.html"); exit; } else { if($Rows1['Password']==$Lo_Password) { //Set Information $Lo_ID= $Rows1['ID']; $Lo_Sprite= $Rows1['Sprite']; $Lo_Sprite1= $Rows1['Sprite1']; $Lo_Sprite2= $Rows1['Sprite2']; $Lo_UserGroup= $Rows1['UserGroup']; $Lo_Title= $Rows1['Title']; $Lo_Banned= $Rows1['Banned']; $Lo_Posts= $Rows1['Posts']; $Lo_Points= $Rows1['Points']; $Lo_EXP= $Rows1['EXP']; $Lo_NEXP= $Rows1['NEXP']; $Lo_Level= $Rows1['Level']; $Lo_Poké= $Rows1['Poké']; $Lo_Email= $Rows1['Email']; $Lo_Gender= $Rows1['Gender']; $Lo_Score= $Rows1['Score']; $Lo_Wins= $Rows1['Wins']; $Lo_Losses= $Rows1['Losses']; $Lo_Battles= $Rows1['Battles']; $Lo_Ribbons= $Rows1['Ribbons']; $Lo_ContestLevel= $Rows1['ContestLevel']; $Lo_ContestEXP= $Rows1['ContestEXP']; $Lo_ContestNEXP= $Rows1['ContestNEXP']; $Lo_ContestWins= $Rows1['ContestWins']; $Lo_ContestLosses= $Rows1['ContestLosses']; $Lo_Contests= $Rows1['Contests']; $Lo_ContestPoints= $Rows1['ContestPoints']; $Lo_AmountBadges= $Rows1['AmountBadges']; $Po_PokémonOwned= $Rows1['PokémonOwned']; if($Lo_Banned=="Yes") { $Lo_Banned="Banned"; } else { $Lo_Banned="Not Banned"; } echo "Welcome back, $Lo_Username! You have been successfully logged in. Continue to the Bottom to go to the Member's Section.<br />"; session_register(Username); session_register(UserID); $_SESSION['Username']= $Lo_Username; $_SESSION['UserID']= $Lo_ID; ?> <html> <hr> <b>Trainer Information</b><br> <hr> <img src="<?PHP echo "$Lo_Sprite1/$Lo_Sprite2/$Lo_Sprite"; ?>" alt="<?PHP echo "$Lo_Username"; ?>"><br> <b>Trainer Name:</b> <?PHP echo "$Lo_Username"; ?><br> <b>Trainer ID:</b> <?PHP echo "$Lo_ID"; ?><br> <b>Trainer Level:</b> <?PHP echo "$Lo_Level"; ?><br> <b>Trainer EXP:</b> <?PHP echo "$LO_EXP/$Lo_NEXP"; ?><br> <b>Trainer Contest Level:</b> <?PHP echo "$Lo_ContestLevel"; ?><br> <b>Trainer Contest EXP:</b> <?PHP echo "$Lo_ContestEXP/$Lo_ContestNEXP"; ?><br> <b>Trainer IP:</b> <?PHP echo "$Lo_IP"; ?><br> <b>Trainer Posts:</b> <?PHP echo "$Lo_Posts"; ?><br> <b>Trainer Points:</b> <?PHP echo "$Lo_Points"; ?><br> <b>Trainer Ribbons:</b> <?PHP echo "$Lo_Ribbons"; ?><br> <b>Trainer Title:</b> <?PHP echo "$Lo_Title"; ?><br> <b>Trainer Status:</b> <?PHP echo "$Lo_Banned"; ?><br> <b>Trainer Group:</b> <?PHP echo "$Lo_UserGroup"; ?><br> <b>Trainer Email:</b> <?PHP echo "$Lo_Email"; ?><br> <b>Trainer Gender:</b> <?PHP echo "$Lo_Gender"; ?><br> <b>Trainer Score:</b> <?PHP echo "$Lo_Score"; ?><br> <b>Trainer Battles:</b> <?PHP echo "$Lo_Battles"; ?><br> <b>Trainer Wins:</b> <?PHP echo "$Lo_Wins"; ?><br> <b>Trainer Losses:</b> <?PHP echo "$Lo_Losses"; ?><br> <b>Trainer Contests:</b> <?PHP echo "$Lo_Contests"; ?><br> <b>Trainer Contest Wins:</b> <?PHP echo "$Lo_ContestWins"; ?><br> <b>Trainer Contest Losses:</b> <?PHP echo "$Lo_ContestLosses"; ?><br> <b>Trainer Contest Points:</b> <?PHP echo "$Lo_ContestPoints"; ?><br> <b>Trainer Badges:</b> <?PHP echo "$Lo_AmountBadges"; ?><br> <b>Pokémon Owned:</b> <?PHP echo "$Lo_PokémonOwned"; ?><br><br> <hr> <b>Login Complete</b><br> <hr> Congratulations, <?PHP echo "$Lo_Username"; ?>, your attempt to Login has been completed successfully. Please, <a href='/index.php'>Continue To The RPG</a>.<br><br> </html> <?PHP //Include Bottom File include("bottom.html"); } } } } } ?> It will say Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /usr/export/www/vhosts/funnetwork/hosting/tpmrpg/login1.php on line 92 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /usr/export/www/vhosts/funnetwork/hosting/tpmrpg/login1.php on line 92 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/export/www/vhosts/funnetwork/hosting/tpmrpg/login1.php on line 94 Line 92 is $Result1= mysql_query("SELECT * FROM Users WHERE Username='$Lo_Username'"); I'm not sure where I could use Die to figure this out... So, please help me. Thanks. Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 12, 2007 Share Posted July 12, 2007 I'm not even going to try to figure out your code. If you indented loops it might almost be readable. The error message "Can't connect to local MySQL server ... " makes me think your database connection code (included in something, I assume) is wrong, or it's never read because it's buried inside a conditional loop that isn't executing before you attempt a database action. Quote Link to comment Share on other sites More sharing options...
Cless Posted July 13, 2007 Author Share Posted July 13, 2007 That sounded insulting. :/ Thanks for your help, though. I think I found out the problem. I have config.php located in the first if part, however, not in the else part. Which would make it so you can't connect. Thanks. Quote Link to comment 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.