craigtolputt Posted July 23, 2008 Share Posted July 23, 2008 Hi Guys, I have a flash website with a news section that loads news stories from a DataBase. It also has a login/registration form which registers users and enters the details into the same DataBase. So i recently moved my site to new servers and this seems to have broken my news section but my registration form still works. So what im trying to get at is if i have entered the same DB settings into both the reg form php and the news story php why would one stop working and not the other.... the connection file for the reg form is here and is included into all the login files.... <?php //YOU MUST FILL THESE OUT IN ORDER TO CONNECT TO THE DATABASE. $host = "localhost"; $usernameDB = "database name"; $passwordDB = "password"; $whichDB = "database name"; //connect with host,username and password $con = mysql_connect($host,$usernameDB,$passwordDB); //if it cant connect echo cant connect and mysql_error; if (!$con) { echo "unable to connect to DB"; echo mysql_error($con); exit(); } //select the database $db = mysql_select_db($whichDB); //if it cant open the DB, echo cant open DB and echo mysql_error if (!$db) { echo "unable to open DB"; echo mysql_error($db); exit(); } ?> and this is how its used... <?php //include the connect script include "connect.php"; /*THIS VARIABLE IS WHAT TABLE YOU ARE USING...IF YOU USED MY SQL FILE, THEN YOUR DEFAULT TABLE*/ /*NAME SHOULD BE 'userv2' AND YOU DO NOT NEED TO CHANGE ANYTHING, BUT IF YOU MADE YOUR OWN TABLE,*/ /*CHANGE THIS VARIABLE.*/ $tableName = "usersv2"; //Post all of the users information (md5 Encrypt the password) $username = $_POST['username']; $password = md5($_POST['password']); $passwordsend = ($_POST['password']); $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $email = $_POST['email']; $phone = $_POST['phone']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; //Custom function to check to see if email domain is equal to ".pnn.police.uk" //phpfreaks.com rules! function check_email($email) { return (substr(trim($email), -14) == '.pnn.police.uk'); } //Generate confKey (this is used to determine which user it is when the user forget's their password. function createConfKey() { $chars = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $key = ''; while ($i <= 31) { $num = rand() % 33; $tmp = substr($chars, $num, 1); $key = $key . $tmp; $i++; } return $key; } if(check_email($email)) { //Start check email $thekey = createConfKey(); //$theKey is the random 32 character string and then $confKey is the random 32 character string with md5 encryption. $confKey = md5($thekey); //grab all the usernames in the table $sql1 = mysql_query("SELECT * FROM $tableName WHERE username = '$username'"); //grab all the emails in the table $sql2 = mysql_query("SELECT * FROM $tableName WHERE email = '$email'"); //get number of results from both queries $row1 = mysql_num_rows($sql1); $row2 = mysql_num_rows($sql2); //if there is a result it will be either 1 or higher if($row1 > 0 || $row2 > 0) { //echo username or email is already in use and deny registration. echo "&msgText=Username or email already in use!"; } else { //if there was no existing username or email, insert all their information into the database. $insert = mysql_query("INSERT INTO $tableName (username,password,firstName,lastName,email,phone,address,city,state,zip,confKey) VALUES ('$username','$password','$firstName','$lastName','$email','$phone','$address','$city','$state','$zip','$confKey')") or die(mysql_error()); //This is required for and HTML email to be sent through PHP. $headers = "From: admin@redwebsecurity.com\r\n"; $headers.= "Content-Type: text/html; charset=ISO-8859-1 "; $headers .= "MIME-Version: 1.0 "; /******HERE YOU CAN EDIT WHAT YOU WANT THE EMAIL TO SAY WHEN THEY FORGET THEIR PASSWORD******/ /* */ /*PHP Explained: */ /*$msg are all the same variable, however, when you set the first one to just '=' and the */ /*second one to '.=' it basically concatinates the two variables. For example: */ /* */ /* */ /* $a = 1; */ /* $a .= 2; */ /* $a .= 3; */ /* echo $a; */ /* */ /* This will echo: 123 */ /* */ /* */ /* Be sure to include $firstName & $lastName somewhere in the message so the user knows */ /* what the message is */ /* */ /* */ /* */ /********************************************************************************************/ $msg = "<a href=\"http://www.redwebsecurity.com\"><img src=\"http://www.tktest.co.uk/redweb/images/small_logo.gif\" alt=\"RedWeb Security\" width=\"137\" height=\"63\" border=\"0\" /></a><br/><br>"; $msg .= "Hello $firstName $lastName,<br/>"; $msg .= "We would like to thank you for joining our web site.<br/><br>"; $msg .= "Your Username is: $username<br/>"; $msg .= "Your Password is: $passwordsend<br/><br>"; $msg .= "Please keep these safe and if you have any questions, contact us at <br><br>"; $msg .= "<a href=\"mailto:admin@redwebsecurity.com\">admin@redwebsecurity.com</a>."; $msg .= "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td align=\"right\" valign=\"bottom\"><a href=\"http://www.redwebsecurity.com\"><img src=\"http://www.tktest.co.uk/redweb/images/large_logo.gif\" alt=\"RedWeb Security | www.redwebsecurity.com\" width=\"298\" height=\"129\" border=\"0\" /></a></td> </tr> </table> <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td height=\"15\"></td> </tr> </table></td> </tr> <tr> <td height=\"44\" align=\"right\" bgcolor=\"#CC0033\"><img src=\"http://www.tktest.co.uk/redweb/images/detect_deter_defend.gif\" alt=\"Detect, Deter, Defend\" width=\"313\" height=\"44\" /></td> </tr> <tr> <td height=\"12\"></td> </tr> <tr> <td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td> </td> <td><a href=\"http://www.redwebsecurity.com\"><img src=\"http://www.tktest.co.uk/redweb/images/small_logo_scto.gif\" alt=\"RedWeb S.C.T.O.\" width=\"117\" height=\"63\" border=\"0\" /></a></td> <td><a href=\"http://www.extremetrackers.com\"><img src=\"http://www.tktest.co.uk/redweb/images/small_logo_extreme_trackers.gif\" alt=\"Extreme Trackers\" width=\"125\" height=\"63\" border=\"0\" /></a></td> <td><a href=\"http://www.safehomes.co.uk\"><img src=\"http://www.tktest.co.uk/redweb/images/small_logo_safe_homes_uk.gif\" alt=\"Safe Homes UK\" width=\"110\" height=\"63\" border=\"0\" /></a></td> <td><a href=\"http://www.securedbydesign.com\"><img src=\"http://www.tktest.co.uk/redweb/images/small_logo_secured_by_design.gif\" alt=\"Police | Secured by Design\" width=\"74\" height=\"63\" border=\"0\" /></a></td> </tr> </table></td> </tr> <tr> <td height=\"12\"></td> </tr> <tr> <td><p><font face=\"Gill Sans MT Pro Medium\" color=\"#ce0a2c\" pointsize=\"14\">RedWeb Security</font> <font face=\"Gill Sans MT Pro Medium\" color=\"#898989\" pointsize=\"14\">(UK) Ltd is a MOD DESO Charter Member</font></p> <p><font face=\"Gill Sans MT Pro Heavy\" color=\"#898989\" pointsize=\"14\">Detect Deter Defend : </font><font face=\"Gill Sans MT Pro Medium\" color=\"#898989\" pointsize=\"14\">empowering the public and business alike to assist the authorities in forensically bringing assailants and perpetrqtors to justice.</font></p> <p><font face=\"Gill Sans MT Pro Medium\" color=\"#135597\" pointsize=\"14\">Safe Homes UK,</font> <font face=\"Gill Sans MT Pro Medium\" color=\"#898989\" pointsize=\"14\">registered in England and Wales No: 3016998</font><br /> <font face=\"Gill Sans MT Pro Medium\" color=\"#ce0a2c\" pointsize=\"14\">RedWeb Security </font><font face=\"Gill Sans MT Pro Medium\" color=\"#898989\" pointsize=\"14\">is the trading name of RedWeb Security (UK) Limited, registered in England and Wales No: 4832392</font></p> <p><font face=\"Gill Sans MT Pro Heavy\" color=\"#898989\" pointsize=\"14\">THIS EMAIL MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED INFORMATION.</font> <font face=\"Gill Sans MT Pro Medium\" color=\"#898989\" pointsize=\"14\">It is only intended for the addressee. If you are not the addressee,<br /> the disclosure, copying or delivering of this to anyone else is strictly prohibited and maybe unlawful. If you receive this e-mail by mistake please notify the<br /> sender immediately by e-mail or telephone.</font></p></td> </tr> </table>"; mail($email,"Thanks for Registering!",$msg,$headers); //and echo "Successfully registered!" and take them to a "thanks for registering" frame in flash echo "&msgText=Successfully registered!"; echo "&nameText=$firstName"; } } else { echo "&msgText=Please enter a valid police email address!"; //error message to display if $email doesnot contain ".pnn.police.uk" } ?> but for the news story section it has the DB connection in all the files like this... <?php // include the Database classes require_once('classes/database.php'); // escape quotes and apostrophes if magic_quotes_gpc off if (!get_magic_quotes_gpc()) { foreach($_POST as $key=>$value) { $temp = addslashes($value); $_POST[$key] = $temp; } } // if ($_POST['action'] == 'loadLatestStories') { // code for retrieving full list $sql = 'SELECT * FROM cmsnewsv2 ORDER BY story_ID desc LIMIT 0,100'; echo getStoryList($sql); } // get list of stories function getStoryList($sql) { $db = new Database('localhost','database name','password','database name'); $result = $db->query($sql); $numrows = $result->num_rows; $storylist = "total=$numrows"; $counter = 0; while ($row = $result->fetch_assoc()) { //$row['story_date'] = date('l jS'); $storylist .= '&story_ID'.$counter.'='.$row['story_ID']; $storylist .= '&story_title'.$counter.'='.urlencode($row['story_title']); $storylist .= '&story_body'.$counter.'='.urlencode($row['story_body']); $storylist .= '&story_postedby'.$counter.'='.urlencode($row['story_postedby']); $storylist .= '&story_photo'.$counter.'='.urlencode($row['story_photo']); $storylist .= '&story_date'.$counter.'='.urlencode($row['story_date']); $storylist .= '&story_link'.$counter.'='.urlencode($row['story_link']); $counter++; } $db->close(); return $storylist; } ?> Does anyone know why one works and the other doesnt?? The thing is on the old server they both work but instead of having the host as localhost it had the server name like this...... mysql1067.servage.net cheers in advance ??? ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/116201-solved-database-connection-error/ Share on other sites More sharing options...
craygo Posted July 23, 2008 Share Posted July 23, 2008 look at your db class and make sure your variables are in the right locations. $db = new Database('localhost','database name','password','database name'); It is probably a mistype but you have database name in there twice. want to make sure your values are in the right place Ray Quote Link to comment https://forums.phpfreaks.com/topic/116201-solved-database-connection-error/#findComment-597541 Share on other sites More sharing options...
craigtolputt Posted July 23, 2008 Author Share Posted July 23, 2008 Cheers, I did check that first. I have found the problem and its a php version error i change the version files and it works wa hoooo! cheers Quote Link to comment https://forums.phpfreaks.com/topic/116201-solved-database-connection-error/#findComment-597564 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.