Jump to content

Recommended Posts

Hello,

 

I have just swapped servers and everything is working fine except for one thing. This code is generating errors.

 

<?php

session_start();

@ $db = mysql_pconnect("localhost", "username", "password");

mysql_select_db("databasename");

$usernam = $_REQUEST['usernam'];
$passwrd = $_REQUEST['passwrd'];

$query = "select * from tbllogin where user = '".$usernam."' and pass = '".$passwrd."'";

$result = mysql_query($query);
$num_results = mysql_num_rows($result);

 

It is generating the following error when username and password is entered:

 

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/g/r/sitename/public_html/html/checklogin.php on line 7

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'UNKNOWN_USER'@'localhost' (using password: NO) in /home/g/r/sitename/public_html/html/checklogin.php on line 14

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/g/r/sitename/public_html/html/checklogin.php on line 14

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/g/r/sitename/public_html/html/checklogin.php on line 15

 

I am sure it is something really simple, I can't seem to make any headway on it. Would appreciate some help if anyone can.

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/53306-swapping-server-code-problem/
Share on other sites

I would have done this:

 

<?php

session_start();

@ $db = mysql_pconnect("localhost", "username", "password");

mysql_select_db("databasename",$db);

$usernam = $_REQUEST['usernam'];
$passwrd = $_REQUEST['passwrd'];

$query = "select * from tbllogin where user = '".$usernam."' and pass = '".$passwrd."'";

$result = mysql_query($query);
$num_results = mysql_num_rows($result);

I would have done this:

 

<?php

session_start();

@ $db = mysql_pconnect("localhost", "username", "password");

mysql_select_db("databasename",$db);

$usernam = $_REQUEST['usernam'];
$passwrd = $_REQUEST['passwrd'];

$query = "select * from tbllogin where user = '".$usernam."' and pass = '".$passwrd."'";

$result = mysql_query($query);
$num_results = mysql_num_rows($result);

 

I tried this and it didn't work. Thank you for the suggestion. I will remove the @ and report back.

Removing the @ threw up the following:

 

Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'xxxx'@'localhost' (using password: YES) in /home/g/r/sitename/public_html/html/checklogin.php on line 5

 

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'UNKNOWN_USER'@'localhost' (using password: NO) in /home/g/r/sitename/public_html/html/checklogin.php on line 7

 

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/g/r/sitename/public_html/html/checklogin.php on line 7

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'UNKNOWN_USER'@'localhost' (using password: NO) in /home/g/r/sitename/public_html/html/checklogin.php on line 14

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/g/r/sitename/public_html/html/checklogin.php on line 14

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/g/r/sitename/public_html/html/checklogin.php on line 15

looks like mysql stuff is off, not php.

 

is the capitalization the same before and now? your previous server may have been more laid back about it due to settings (I've had that situation) but this one might need things to be exact, a capital letter can make all the difference on 2 things that worked previously, but really shouldn't have been working

are your normal connections working?

 

as in, can you make a connection to the database and query for something (anything), it looks like from the error on line7 the login script is not to blame, something is going wrong with the connection, if not capitalization, misspelling, etc then perhaps the new database is not setup yet.

 

are you absolutely sure the new database is on the new server? sometimes it takes a day to fully propagate,  but can you log in and view data, etc via phpmyadmin or a similar program?

My 2 cents

 

Looks like the username or password are incorrect.

 

Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'xxxx'@'localhost' (using password: YES) in /home/g/r/sitename/public_html/html/checklogin.php on line 5

 

 

If username or password are not right, then you will not be able to select the db

 

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'UNKNOWN_USER'@'localhost' (using password: NO) in /home/g/r/sitename/public_html/html/checklogin.php on line 7

 

 

My suggestion is to ensure that the database is set up with the same DB name, Username & Password. Try creating a new script in a new page and attempt to make a connection, and select a database. If you can do those items, then try selecting data from the database. If that works, then find what is different. If it don't work, then re-check your host,username,password & permissions.

 

 

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.