flipside Posted May 9, 2010 Share Posted May 9, 2010 Hello everyone, I am pretty new to PHP and currently working on a website which requires a Account creation page. at the moment the page is online at: http://total-war.net/websitenieuw/create-an-account.php . Everytime i submit something in my form it gives this error: "Could NOT connect to db, please check the config part of the file!" This is my entire code in my .php file: <?php /*Config*/ $realmd = array( 'db_host'=> '------', //ip of db realm 'db_username' => '-----',//realm user 'db_password' => '------',//realm password 'db_name'=> '------',//realm db name ); ///////////////Start script////////////////// /* Function name: CHECK FOR SYMBOLS Description: return TRUE if matches. ( True = OK ) ( False = NOT OK) */ function check_for_symbols($string){ $len=strlen($string); $alowed_chars="abcdefghijklmnopqrstuvwxyzæøåABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ1234567890"; for($i=0;$i<$len;$i++)if(!strstr($alowed_chars,$string[$i]))return TRUE; return FALSE; } /* Function name: OUTPUT USERNAME:PASSWORD AS SHA1 crypt Description: obious. */ function sha_password($user,$pass){ $user = strtoupper($user); $pass = strtoupper($pass); return SHA1($user.':'.$pass); } if ($_POST['registration']){ /*Connect and Select*/ $realmd_bc_new_connect = mysql_connect($realmd[db_host],$realmd[db_username],$realmd[db_password]); $selectdb = mysql_select_db($realmd[db_name],$realmd_bc_new_connect); if (!$realmd_bc_new_connect || !$selectdb){ echo "Could NOT connect to db, please check the config part of the file!"; die; } /*Checks*/ $username = $_POST['username']; $password = sha_password($username,$_POST['password']); $email = $_POST['email']; $qry_check_username = mysql_query("SELECT username FROM `account` WHERE username='$username'"); if (check_for_symbols($_POST[password]) == TRUE || check_for_symbols($username) == TRUE || mysql_num_rows($qry_check_username) != 0){ echo "<body text=\"0098f8\" bgcolor=\"ffffff\" link=\"61100c\" alink=\"61100c\" vlink=\"61100c\"> <center> <p>Error</p> <p>Please try again.</p> <p>Numbers don't work in Username or Password.</p> <br> <a href=regacc.php>Back</a> </center> </body>"; }else{ // mysql_query("INSERT INTO account (username,sha_pass_hash,email,expansion) VALUES ('$username','$password','$email','0')");// Insert into database. echo "<body text=\"00d514\" bgcolor=\"ffffff\" link=\"61100c\" alink=\"61100c\" vlink=\"61100c\"> <center> <p>This page is currently inactive and is not for use.</p> <br> <a href=http://boxxyserver.110mb.com/regacc.php>Retrurn to Main Page</a> </center> </body>"; } }else{ ///////////////Stop script, Start HTML////////////////// ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="imagetoolbar" content="false"/> <title>Total-War.net</title> <link rel="stylesheet" type="text/css" media="screen, projection" href="css/master.css"/> <link href="css/container.css" rel="stylesheet" type="text/css" /> <link href="css/banner.css" rel="stylesheet" type="text/css" /> <link href="css/menu.css" rel="stylesheet" type="text/css" /> <link href="css/links.css" rel="stylesheet" type="text/css" /> <link href="css/content.css" rel="stylesheet" type="text/css" /> <link href="css/content-text.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/common.js"></script> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript"> var $j = jQuery.noConflict(); var processingStr = "processing"; </script> </head> <body bgcolor="#000000" class="de"> <div id="container"> <div id="banner"></div> <div id="content"><img src="images/create-an-account.png" width="487" height="25" /><br /><br /> <div id="content-text"> <div class=""> <br /> <form id="loginForm" class="submitForm" name="loginForm" autocomplete="off" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <div class="formRow accountName"> <label class="formLabel" for="accountName" style="margin-bottom:1px">Username:</label> <input name="username" type="text" class="text" id="username" tabindex="1" maxlength="320" /> </div> <div class="formRow email"> <label class="formLabel" for="email">Email Address:</label> <input id="email" name="email" maxlength="26" type="text" tabindex="2" autocomplete="off" class="text" /> </div> <div class="formRow password"> <label class="formLabel" for="password">Password:</label> <input id="password" name="password" maxlength="26" type="password" tabindex="2" autocomplete="off" class="text" /> </div> <center> </center> <div align="center"> <input name="registration" TYPE="image" value="submit" SRC="images/account.png" HEIGHT="40" WIDTH="177" BORDER="0" ALT="Submit Form"> </div> <div class="Back"> <br> <br> <!-- <a href="http://boxxyserver.110mb.com/regacc.php">Return to Main Page</a> </p> --> </div> </form> </div> </div> <br /> <br /><br /><br /><br /> </div> <div id="menu"> <div id="links"> <a href="home.php">Home</a> <br /> <a href="patch-notes.php">Patch notes</a> <br /> <a href="create-an-account.php">Create an Account</a> <br /> <a href="how-to-connect.php">How to Connect</a> <br /> <a href="server-info.php">Server Information</a> <br /> <a href="downloads.php">Downloads</a> <br /> <a href="faq.php">FAQ</a> <br /> <a href="donate.php">Donate</a> <br /> <a href="http://www.total-war.net/forum">Forum</a> <br /> <a href="staff.php">Staff</a> <br /> <a href="contact-us.php">Contact us</a> </div> </div> </div> </div> </body> </html> <?php // Do not remove this;) } ?> If somebody could check it, all your help will be very appreciated. With kind regards, Levi West. Link to comment https://forums.phpfreaks.com/topic/201161-help-could-not-connect-to-db-account-creation-page/ Share on other sites More sharing options...
Pikachu2000 Posted May 9, 2010 Share Posted May 9, 2010 Might not be such a great idea to post all the database connection credentials on the internet, as you have done. I'd recommend editing them out. Link to comment https://forums.phpfreaks.com/topic/201161-help-could-not-connect-to-db-account-creation-page/#findComment-1055395 Share on other sites More sharing options...
flipside Posted May 9, 2010 Author Share Posted May 9, 2010 Yes already done it Link to comment https://forums.phpfreaks.com/topic/201161-help-could-not-connect-to-db-account-creation-page/#findComment-1055413 Share on other sites More sharing options...
kenrbnsn Posted May 9, 2010 Share Posted May 9, 2010 Instead of doing <?php $realmd_bc_new_connect = mysql_connect($realmd[db_host],$realmd[db_username],$realmd[db_password]); $selectdb = mysql_select_db($realmd[db_name],$realmd_bc_new_connect); if (!$realmd_bc_new_connect || !$selectdb){ echo "Could NOT connect to db, please check the config part of the file!"; die; }?> Put a check after each MySQL statement which will tell you which statement died and why: <?php $realmd_bc_new_connect = mysql_connect($realmd[db_host],$realmd[db_username],$realmd[db_password]) or die("Problem connecting to MySQL<br>" . mysql_error()); $selectdb = mysql_select_db($realmd[db_name],$realmd_bc_new_connect) or die("Problem selecting the database<br>" . mysql_error()); ?> Ken Link to comment https://forums.phpfreaks.com/topic/201161-help-could-not-connect-to-db-account-creation-page/#findComment-1055415 Share on other sites More sharing options...
flipside Posted May 9, 2010 Author Share Posted May 9, 2010 I've edited the code and now i get this message: Problem connecting to MySQL Lost connection to MySQL server at 'reading initial communication packet', system error: 111 Link to comment https://forums.phpfreaks.com/topic/201161-help-could-not-connect-to-db-account-creation-page/#findComment-1055422 Share on other sites More sharing options...
kenrbnsn Posted May 9, 2010 Share Posted May 9, 2010 Talk to your Host. This looks like a system problem. Ken Link to comment https://forums.phpfreaks.com/topic/201161-help-could-not-connect-to-db-account-creation-page/#findComment-1055424 Share on other sites More sharing options...
blukkie Posted May 9, 2010 Share Posted May 9, 2010 Hi, I'm the host of the Database so I just wanted to join in into this issue. The problem we're having is rather strange. On my free website host, everything connects fine and well. When my friends want to connect to my Database, it all works. But when we upload the script to our website host, it all stops working. I suspect this problem is being caused by our website host, rather than me looking at what I said above. Link to comment https://forums.phpfreaks.com/topic/201161-help-could-not-connect-to-db-account-creation-page/#findComment-1055430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.