Jump to content

Recommended Posts

I made my first PHP and MySql web site on my computer, the database access is ('localhost', 'user', 'password') obviously...so when I uploaded my web site to my hosting, and created the database what do I change localhost to?! I get the error, access denied for user @ localhost. This is a newbie question but surprisingly hard to find on a search engine,

 

thank you :)

Link to comment
https://forums.phpfreaks.com/topic/75511-solved-localhost/
Share on other sites

Thanks guys I got it :) now the problem is that when I try and register a new user, it gives me my "user name already exists" message, even though there aren't any user names on the database.

 

if(mysql_affected_rows() > 0)
{
$_SESSION['login'] = $_POST['login'];
$login='Thank you for registering ' . $_SESSION['login'];
}
else
{
$login= 'The user name you have requested already exists.';
}

mysql_close($db);

}

 

Anybody have any ideas why? =/

It worked perfectly on my computer.

 

Link to comment
https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381979
Share on other sites

<?php
$login='Your password fields do not match! Go back and try again.';
/*simple checking of the data*/
if(isset($_POST['login']) && isset($_POST['pass']) && ($_POST['pass'] == $_POST['confirm']))
{

/*Connection to database logindb using your login name and password*/
$db=mysql_connect('localhost','a5491461_admin','admin') or die(mysql_error());
mysql_select_db('test');

/*additional data checking and striping*/
$_POST['login']=mysql_real_escape_string(strip_tags(trim($_POST['login'])));
$_POST['pass']=mysql_real_escape_string(strip_tags(trim($_POST['pass'])));

mysql_query("INSERT INTO login SET login='{$_POST['login']}',pass='{$_POST['pass']}'",$db);

/*If the database has been updated*/
if(mysql_affected_rows() > 0)
{
$_SESSION['login'] = $_POST['login'];
$login='Thank you for registering ' . $_SESSION['login'];
}
else
{
$login= 'The user name you have requested already exists.';
}

mysql_close($db);

}
echo $login
?>

 

I only posted a bit because it works perfectly on my computer, here is the whole code for the submit register page.

Link to comment
https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381982
Share on other sites

you aren't giving your query to mysql_affected_rows()

 

needs to be

$theQuery = mysql_query("INSERT INTO login SET login='{$_POST['login']}',pass='{$_POST['pass']}'",$db);

/*If the database has been updated*/
if(mysql_affected_rows($theQuery) > 0)

Link to comment
https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381995
Share on other sites

it should but actually if I was writing a already user exist script the pseudocode would be something like this

 

 

result = select user from usertable where username='username'

if (result) 
   print "username already exists"
else 
 my insert statement 
 print "registration completed
end if 

Link to comment
https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381996
Share on other sites

I changed it and got this:

 

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/a5491461/public_html/submitregister.php on line 112

The user name you have requested already exists.

 

Why would it have worked 100% fine on my computer but changed when I uploaded it?

Link to comment
https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382005
Share on other sites

yeah you're right..

I don't use affected_rows all that much, I'm too used to num_rows...for some reason I was under that impression.

 

can't understand why an irregular formatted INSERT statement works perfectly like that, but anyway

try putting an error message in there

 

mysql_query("INSERT INTO login SET login='{$_POST['login']}',pass='{$_POST['pass']}'",$db) or die(mysql_error());

 

 

Link to comment
https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382021
Share on other sites

Okay I changed it, and got this message again:

 

"The user name you have requested already exists."

 

At least there isn't any mysql error. This worked fine on my computer, so the issue can't be that big especially since the output is my own code.

 

Thanks for you help anyway dude.

Link to comment
https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382023
Share on other sites

well some code for you

 

<?php
$login='Your password fields do not match! Go back and try again.';
/*simple checking of the data*/
if(isset($_POST['login']) && isset($_POST['pass']) && ($_POST['pass'] == $_POST['confirm']))
{

/*Connection to database logindb using your login name and password*/
$db=mysql_connect('localhost','a5491461_admin','admin') or die(mysql_error());
mysql_select_db('test');

/*additional data checking and striping*/
$_POST['login']=mysql_real_escape_string(strip_tags(trim($_POST['login'])));
$_POST['pass']=mysql_real_escape_string(strip_tags(trim($_POST['pass'])));

$result = "select login from where login ='{$_POST['login']}'";

/*If the database has been updated*/
if(mysql_num_rows($result) > 0)
{
$login= 'The user name you have requested already exists.';	
}
else
{
mysql_query("INSERT INTO login SET login='{$_POST['login']}',pass='{$_POST['pass']}'",$db);
$_SESSION['login'] = $_POST['login'];
$login='Thank you for registering ' . $_SESSION['login'];
}

mysql_close($db);

}
echo $login
?>

 

enjoy!!

Link to comment
https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382024
Share on other sites

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.