Jump to content

[SOLVED] Site working with localhost but not web host


Recommended Posts

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

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.

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

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

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.

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

 

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.