Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: sohaibtoosy (---.dsl.net.pk)
Date: August 14, 2012 07:47AM

my pages work fine on my pc but when i uploaded the pages and the database as .sql, and then try to login it gives such errors:

THE WEBSITE IS [www.sohaibtoosy.zxq.net] IF YOU WANT TO SEE YOURSELF

Warning: mysql_connect() [function.mysql-connect]: Access denied for user '773766_sohaib@lo'@'192.168.1.1' (using password: YES) in /www/zxq.net/s/o/h/sohaibtoosy/htdocs/index.php on line 48

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /www/zxq.net/s/o/h/sohaibtoosy/htdocs/index.php on line 49

Warning: mysql_query() [function.mysql-query]: Access denied for user 'vhostswww'@'192.168.1.1' (using password: NO) in /www/zxq.net/s/o/h/sohaibtoosy/htdocs/index.php on line 50

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /www/zxq.net/s/o/h/sohaibtoosy/htdocs/index.php on line 50

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /www/zxq.net/s/o/h/sohaibtoosy/htdocs/index.php on line 53

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: RiggsFolly (---.as13285.net)
Date: August 14, 2012 10:32AM

Can you post the PHP code for the mysql_connect() ... changing the password of course.



Edited 1 time(s). Last edit at 08/14/2012 10:49AM by RiggsFolly.

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: sohaibtoosy (---.dsl.net.pk)
Date: August 14, 2012 02:13PM

that is the complete copy of my code. only 'localhost', 'root' and password were changed at time of upload, other wise of localhost (in my pc) it works fine


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[www.w3.org];
<html xmlns="[www.w3.org];
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcom Page</title>
<link href="babycss.css" rel="stylesheet" type="text/css" />
</head>
<div id="banner"></div>
</head>

<body>
<form action="index.php" method="post">
<div id="sidebar">
<br />
<div id="header">
<h3> You may <a href="signup.php"> click here </a> to signup if<br />
already not a member </h3>
</div><br />
<br />

</div>
<center>
<h1> Enter ID and Password if already a member</h1>
<table>
<tr>
<td>Enter Login ID </td> <td> <input type = "text" name = "txtID" /></td>
</tr>
<tr>
<td> Enter Password </td> <td> <input type = "text" name = "txtPass"/> </td>
</tr>
<tr>
<td></td>
<td>
<input type = "submit" name = "btnLogin" value = "Login"/>
</td>
</tr>

<p>&nbsp;</p>
<p>&nbsp;</p>
</center>
</form>

<?php


if(isset($_POST['btnLogin']))
{
$con = mysql_connect('sohaibtoosy.zxq.net', 'sohaib','***********'or die ("not connected"winking smiley);
mysql_select_db('cvDatabase',$con);
$qry=mysql_query("select * from logintable"winking smiley ;
$userid = $_POST['txtID'];
$userpass = $_POST['txtPass'];
while($search1=mysql_fetch_row($qry))
{
if($userid == $search1[1] && $userpass == $search1[2])
{
header('location:cvUploadForm.php');
}
else
if($userid != $search1[1] || $userpass != $search1[2])
{
echo"<tr>";
echo"<td></td><td>";
echo "<div id='errorBox'>";
echo " <h3>Login ID or Password is invalid </h3>";
break;
echo "</div>";
echo"</td>";
echo"</tr>";
}
}
}
?>
</table>
</body>
</html>

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: RiggsFolly (---.as13285.net)
Date: August 14, 2012 03:19PM

OK,

A couple of things:

1. I assume you did a copy and paste in which case the code is wrong:
The mysql_connect does not have a closing bracket ).

$con = mysql_connect('sohaibtoosy.zxq.net', 'sohaib','***********'or die ( "not connected" );
change to
$con = mysql_connect( 'sohaibtoosy.zxq.net', 'sohaib', '***********' ) or die ( 'not connected' );


I think, unless your hosting package says differently, that you should try changing the mysql_connect as follows:

$con = mysql_connect( 'localhost', 'sohaib', 'password' ) or die( "not connected" );


These changes should also work on WAMP as the script should be connecting to a mysql server on the localhost machine. Therefore you will not need to change this code when you copy code from test to live.

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: sohaibtoosy (---.dsl.net.pk)
Date: August 14, 2012 05:16PM

I did these changes and uploaded but still no luck . . . sad smiley you might take control sometime if you have TV . . .

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: RiggsFolly (---.as13285.net)
Date: August 16, 2012 11:26AM

I see you are online, do you have the time for a TV session?

If so send me a Private Message with your TV ID and Password

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: sohaibtoosy (---.dsl.net.pk)
Date: August 17, 2012 09:32AM

I've got it to work . . . the connection is fine now but after the login n pass is confirmed, "header('location:cvUploadForm.php');" gives the error

Warning: Cannot modify header information - headers already sent by (output started at /www/zxq.net/s/o/h/sohaibtoosy/htdocs/index.php:12) in /www/zxq.net/s/o/h/sohaibtoosy/htdocs/index.php on line 69

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: RiggsFolly (---.ppp.as43234.net)
Date: August 17, 2012 09:55AM

Good,

I think you need to hit the books man.

You are getting that message because your PHP code is after your HTML and in this specific case your php is calling the header() funtion.
By the time you get to run the PHP the server has already sent headers and most of the page to the browser.

Order your pages like this

<?php

... code ...

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[www.w3.org];
<html xmlns="[www.w3.org];
... all the html

.. <?php echo $var; ?>

...
</html>

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: sohaibtoosy (---.dsl.net.pk)
Date: August 17, 2012 10:02AM

yes perhaps that is the reason because <form action "blah blah" . . . have sent the header . . .

isn't that what you mean . .

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: sohaibtoosy (---.dsl.net.pk)
Date: August 17, 2012 10:07AM

actually its login form and before taking login and password from user, i can't use php . . otherwise whether or not the login n pass matches, the next page will be loaded for sure

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: stevenmartin99 (Moderator)
Date: August 17, 2012 10:16AM

you cant output ANYTHING( including whitespace) if you need to modify the header...

you clearly have if you got this error

need to see the code better...

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]



Edited 2 time(s). Last edit at 08/17/2012 07:24PM by stevenmartin99.

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: RiggsFolly (---.ppp.as43234.net)
Date: August 17, 2012 12:29PM

Hit the books and tutorials.

Download some freely available apps and examine the code.

There is no nice way to say it but your code shows this is your first attempt at coding.


Something you need to know:

On first page load the btnLogin will not even exist in the POST array. In fact there will be no POST array at all because nothing hsa yet been posted back to the server from the form. You can use this knowledge to control your code.

So your isset( $_POST[ 'btnLogin'] ) will be false unless the button was pressed.

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: sohaibtoosy (---.dsl.net.pk)
Date: August 17, 2012 05:30PM

i never knew about white spaces lol . . . . as you taught about the program structure of
<?php
...
...
?>
and then
<html>
...
...
and others . . .
i did it and used ob_start(); in the beginning and YOU ROCK winking smiley

yup its my first time in php . . . m a dot net guy lol


i'll keep in touch bro cos i love to learn grinning smiley

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: RiggsFolly (---.ppp.as43234.net)
Date: August 17, 2012 07:09PM

thats a relief, I thought I might have offended there and that was not my intension.

Options: ReplyQuote
Re: Warning: mysql_connect() [function.mysql-connect]: Access denied for user
Posted by: sohaibtoosy (---.dsl.net.pk)
Date: August 21, 2012 09:20AM

no budy u drove me in the right direction grinning smiley



oh come on IE :-| . . . its works fine in Opera . . .

Options: ReplyQuote


Sorry, only registered users may post in this forum.