MsRedImp Posted October 31, 2007 Share Posted October 31, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/ Share on other sites More sharing options...
~n[EO]n~ Posted October 31, 2007 Share Posted October 31, 2007 It will be localhost on the server too... Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381969 Share on other sites More sharing options...
Zane Posted October 31, 2007 Share Posted October 31, 2007 did the error say whether or not you were using a password.... usually it does... most likely there is a different username/password on your Server's mysql Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381972 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 well try your computer name instead of ''localhost" Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381975 Share on other sites More sharing options...
MsRedImp Posted October 31, 2007 Author Share Posted October 31, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381979 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 would you post the query thats the most important part Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381980 Share on other sites More sharing options...
MsRedImp Posted October 31, 2007 Author Share Posted October 31, 2007 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381982 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 well honestly speaking INSERT INTO login SET login='{$_POST['login']}',pass='{$_POST['pass']} should be INSERT INTO login ( login, pass) VALUES ('{$_POST['login']}','{$_POST['pass']}') you only use set in update statements Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381985 Share on other sites More sharing options...
MsRedImp Posted October 31, 2007 Author Share Posted October 31, 2007 Hmm okay I will change it, but if it worked fine on my computer, will this really fix it? Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381988 Share on other sites More sharing options...
MsRedImp Posted October 31, 2007 Author Share Posted October 31, 2007 It didn't change anything, still get the same message. Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381994 Share on other sites More sharing options...
Zane Posted October 31, 2007 Share Posted October 31, 2007 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) Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381995 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-381996 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 no offense zanus but for mysql_affected_rows you have to give the result link not the query so the result link from mysql query more information available at (our php source) http://php.net/mysql_affected_rows Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382000 Share on other sites More sharing options...
MsRedImp Posted October 31, 2007 Author Share Posted October 31, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382005 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 well MsRedImp it should be like this $result = mysql_query("INSERT INTO login ( login, pass) VALUES ('{$_POST['login']}','{$_POST['pass']}')"); Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382009 Share on other sites More sharing options...
Zane Posted October 31, 2007 Share Posted October 31, 2007 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()); Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382021 Share on other sites More sharing options...
MsRedImp Posted October 31, 2007 Author Share Posted October 31, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382023 Share on other sites More sharing options...
rajivgonsalves Posted October 31, 2007 Share Posted October 31, 2007 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!! Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382024 Share on other sites More sharing options...
MsRedImp Posted October 31, 2007 Author Share Posted October 31, 2007 Thank you very much guys, I got it to work =) Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382026 Share on other sites More sharing options...
fenway Posted October 31, 2007 Share Posted October 31, 2007 can't understand why an irregular formatted INSERT statement works perfectly like that, but anyway You can actually use either syntax. Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382038 Share on other sites More sharing options...
Zane Posted October 31, 2007 Share Posted October 31, 2007 learn something everyday Quote Link to comment https://forums.phpfreaks.com/topic/75511-solved-localhost/#findComment-382260 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.