Ell20 Posted October 31, 2007 Share Posted October 31, 2007 Hey, I decided to transfer my site onto a web host so that I can show people my progress etc. I have uploaded all the files and the database but when I log in it says that the username and password do not match. In an attempt to solve this I registered a new account instead of using one from when I was using it on the local host but this didnt work either. I dont see how it can be a database connect problem as I managed to create a new account, which successfully stored into the databse <?php require_once ('includes/errors.inc'); $page_title = 'MySport'; include ('includes/header.html'); if (isset($_SESSION['user_id'])) { header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/main.php"); ob_end_clean(); exit(); } else { if (isset($_POST['submit'])) { require_once ('mysql_connect.php'); /* Check username is entered */ if (empty($_POST['username'])) { $u = FALSE; echo '<p><font color="red" size="+1">You forgot to enter your username!</font></p>'; } else { $u = escape_data($_POST['username']); } /* Check password is entered */ if (empty($_POST['password'])) { $p = FALSE; echo '<p><font color ="red" size="+1">You forgot to enter your password!</font></p>'; } else { $p = escape_data($_POST['password']); } /* If username and password entered query database to check they match in database */ if ($u && $p) { $query = "SELECT user_id, club_id FROM users WHERE username='$u' AND password=PASSWORD('$p')"; $result = @mysql_query($query); $row = mysql_fetch_array ($result, MYSQL_NUM); /* If they match create session */ if ($row) { $_SESSION['user_id']=$row[0]; $_SESSION['club_id']=$row[1]; ob_end_clean(); /* Redirect to main.php when logged in */ header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/main.php"); exit(); } else { echo '<p><font color="red" size="+1">The username and password do not match</font></p>'; } mysql_close(); } else { echo '<p><font color="red" size="+1">Please try again</font</p>'; } } } ?> <br /> <br /> <table width="70%" align="center" border="0"> <tr> <td width="17.5%" align="center"> <a href="index.php"><img border="0" src="images/home.jpg" width="200" height="30"></a> </td> <td width="17.5%" align="center"> <a href="register.php"><img border="0" src="images/register.jpg" width="200" height="30"></a> </td> <td width="17.5%" align="center"> <a href="registermember.php"><img border="0" src="images/registermember.jpg" width="200" height="30"></a> </td> <td width="17.5%" align="center"> <a href="forgot_password.php"><img border="0" src="images/forgotpassword.jpg" width="200" height="30"></a> </td> </tr> </table> <br /> <br /> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <form action="" method="post" name="form2" id="form2"> <table width="50%" align="center" cellspacing="0" border="0" class="game"> <tr> <th width="100%" colspan=3 align="center">Member Login Guest Login</th> </tr> <tr> <td width="33%">Username: <input type="text" name="username" size="20" maxlength="20" value="<?php if(isset($_POST['username'])) echo $_POST['username']; ?>"/></td> <td width="33%" align="center" rowspan="2"><select name="clubdrop"><option value="">Select Your Club</option> <?php require_once ('mysql_connect.php'); $sql = "SELECT * FROM club"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $club_id = $row["club_id"]; $clubName = $row["clubn"]; $club_id == $OTHER_CLUB_ID ? $sel = 'SELECTED' : $sel = ''; ?> <option value="<?php echo $club_id ?>" <?php echo $sel ?>><?php echo $clubName ?></option> <?php } ?> The error I get is: Username and password do not match Thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/ Share on other sites More sharing options...
Orio Posted October 31, 2007 Share Posted October 31, 2007 First, check if your tables are defined correctly and everything is ok on the database side. By that I mean that all of the columns have the correct name, the length they need, their type etc' If that doesn't help continue on reading... Instead of these lines (line 34-35): $result = @mysql_query($query); $row = mysql_fetch_array ($result, MYSQL_NUM); Write: $result = mysql_query($query) or die($query."<br>".mysql_error()); $row = mysql_fetch_array ($result, MYSQL_NUM) or die(mysql_error()); And tell us if you get any errors. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382279 Share on other sites More sharing options...
Ell20 Posted October 31, 2007 Author Share Posted October 31, 2007 I seem to have it working now, I increased the length of the password to 50 characters in the database and created a new account. Is there a reason why the password field has a * at the start in the database for accounts registered using the webhost: "*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29" Also is there a reason why accounts that I have previously set up from the local host dont work on the web host when I simply export/imported the database from the local host to the web host? Cheers for your help Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382288 Share on other sites More sharing options...
revraz Posted October 31, 2007 Share Posted October 31, 2007 Maybe they got truncated? Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382290 Share on other sites More sharing options...
Ell20 Posted October 31, 2007 Author Share Posted October 31, 2007 Having logged in, the site isnt functioning as it was when I was using it as local host. http://mysport.x10hosting.com Username: Test Password: Test When I add news on the news page and press Create News it takes me to the following page: http://news.php/, how comes it isnt adding in the correct address? Also on all the pages the address has to // e.g http://mysport.x10hosting.com//news.php Any help is very much appreciated Elliot Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382296 Share on other sites More sharing options...
trq Posted October 31, 2007 Share Posted October 31, 2007 is there a reason why accounts that I have previously set up from the local host dont work on the web host when I simply export/imported the database Yes. Because you are using mysql's PASSWORD function which as it clearly states in the manual is not intended to be used by client code. It is an internal function and could be subject to change in implimentation between versions. I would say you may have a different mysql version on you local server as compared to your remote. In short, do not use the PASSWORD() function but use MD5 instead. Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382298 Share on other sites More sharing options...
revraz Posted October 31, 2007 Share Posted October 31, 2007 Try to change this line: /* Redirect to main.php when logged in */ header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/main.php"); to just /* Redirect to main.php when logged in */ header ("Location: main.php"); Or even a META referesh URL Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382300 Share on other sites More sharing options...
Ell20 Posted October 31, 2007 Author Share Posted October 31, 2007 Not working at all now, when I log in it goes to http://index.php I have even changed the code back and its still not made any difference Grr Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382303 Share on other sites More sharing options...
Ell20 Posted October 31, 2007 Author Share Posted October 31, 2007 Scrap that, I forgot I was using a webhost, I needed go back to the starting domain for the changes to take place properly. I just remove / from "/main.php" and it seems to be working now. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382307 Share on other sites More sharing options...
revraz Posted October 31, 2007 Share Posted October 31, 2007 This is from your registermember.php page <form action="/registermember.php" method="post"> The "/" is taking you back one level. Is the registermember.php page on the same level as your index or main page? Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382308 Share on other sites More sharing options...
Ell20 Posted October 31, 2007 Author Share Posted October 31, 2007 Yeah its on the same level, that page seems to be working ok at the moment Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382315 Share on other sites More sharing options...
revraz Posted October 31, 2007 Share Posted October 31, 2007 Seems you my have to go through all your code and get rid of all those, like you suspect. Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382318 Share on other sites More sharing options...
Ell20 Posted October 31, 2007 Author Share Posted October 31, 2007 It should be ok because the actual code reads: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Its working ok for now. Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382323 Share on other sites More sharing options...
trq Posted November 1, 2007 Share Posted November 1, 2007 If you want a page to post to itself all you need is.... <form method="post"> Quote Link to comment https://forums.phpfreaks.com/topic/75561-solved-site-working-with-localhost-but-not-web-host/#findComment-382438 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.