hi im new to php/mysql i have developed a code in asp and converted it to php with asp2php programme. the original solution asp/sqlserver iis works fine..the new solution will be a iis php mysql. mysql server works fine iis works fine however the php wont let me connect to the mysql database i have created..when i connect with asp it does! there must be something missing in the code. i tried all kinds of config
so this is whats happening when i try to connect with php the page returns on itself as if the username and password submitted in the form is wrong or not found. yet when i connect to the same database with asp it goes correctly. when i alter the connection strings (php) i get the error
#1251 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

therefore i go back to my original script which is as follows

//check that user exists and login is correct

// $conn is of type "adodb.connection"

  $conn=@mysql_connect("localhost","root","astra123");
@mysql_select_db("mildmaydemo",$conn);
//root", "astra123"
$RSStudent=$RSStudent_query=@mysql_query(("SELECT StudentID FROM MMStudents where StudentEmailAddress = '"
    .$_POST["EmailAddress"]."' and StudentPassword = '"
    .$_POST["Password"]."'"),$conn);  
$RSStudent=@mysql_fetch_array($RSStudent_query);
  if (($RSStudent==0))
  {

//invalid login

    $TheMessage="Student not found. Re enter the correct email and password.";
  }
    else
  {

//valid entry

as you can see the user is sent back to the logging page when the username and password is not verified against the database...
im sure there is something missing in the code that is preventing it from connecting to the database to retrieve the details..as i say im completely new to php and cant see what is wrong here..
any help would be great!
thanks in advance chris

I edited the post to make the code easier to read.

After mysql_connect(), put this:

if (!$conn) {
   die('Not connected : ' . mysql_error());
}

What version of mysql?? If it is new and php is not new, you might try starting the mysql server with the option --old-passwords. If you use mysqladministrator (gui) you can choose the old passwords option under the security tab.

You can read about it in detail here:

A.2.3. Client does not support authentication protocol

Dance

hi the version of mysql is mysql client version 5.0.0 and the php version is 5. im using windows 2003 and iis 6. My previous error was that the page returned on itself stating that the user was not found. the database, iis odbc are all in place and work fine with ASP. however the php wont let me logg in.
to try and fix this i upgraded the php to 5 and i now get a blank white page returned when i try to logg into the site. the code im using to connect is:
// $conn is of type "adodb.connection"

$conn=@mysql_connect("localhost","root","astra123");
mysql_select_db("mildmaydemo",$conn);
//root", "astra123"

the server name user database name and password are all correct

as im new to mysql +php im not sure if its a code error or a mysql/php version incompatability issue
when i alter the code i get different error messages or as in the latest case i get returned a blank white page with no error message
for example if i remove the "@" in the line

$conn=@mysql_connect("localhost","root","astra123");

i get the error
Fatal error: Call to undefined function mysql_connect() in C:\Inetpub\wwwroot\mildmayphp\index.php on line 22

line 22 in my code is highlighted in bold above

i figure the "@" is a way to prevent ugly error messages presenting on the page
its all very frustrating any help appreciated and thanks in advance
cheers
chris

firstly apologies for the double submission
hi the version of mysql is mysql client version 5.0.0(4.1.10nt-via TCP/IP) and the php version is 5.0.3. im using windows 2003 and iis 6. My previous error was that the page returned on itself stating that the user was not found. the database, iis odbc are all in place and work fine with ASP. however the php wont let me logg in.
to try and fix this i upgraded the php to 5 and i now get a blank white page returned when i try to logg into the site. the code im using to connect is:
// $conn is of type "adodb.connection"

$conn=@mysql_connect("localhost","root","astra123");
mysql_select_db("mildmaydemo",$conn);
//root", "astra123"

the server name user database name and password are all correct

as im new to mysql +php im not sure if its a code error or a mysql/php version incompatability issue
when i alter the code i get different error messages or as in the latest case i get returned a blank white page with no error message
for example if i remove the "@" in the line

$conn=@mysql_connect("localhost","root","astra123");

i get the error
Fatal error: Call to undefined function mysql_connect() in C:\Inetpub\wwwroot\mildmayphp\index.php on line 22

line 22 in my code is highlighted in bold above

i figure the "@" is a way to prevent ugly error messages presenting on the page
its all very frustrating any help appreciated and thanks in advance
cheers
chris btw i have reset the old password in mysqladministrator and reset it to old password from a dos prompt. i tried those options( which didnt work) before i upgraded to php 5

For php5, did you use the msi installer or download the zip file for installation?

Dance

i installed from zip and copied libmysql.dll and php5ts.dll to win/system 32. my php.info page works ok i was reccomended to configure my php.ini file to recognise mysql ie

;extension=php_msql.dll
extension=php_mysql.dll
;extension=php_oci8.dll

yet still my login php page gives the error
Fatal error: Call to undefined function mysql_connect() in C:\Inetpub\wwwroot\mildmayphp\index.php on line 22

and my phpmyadmin page gives the error

cannot load mysql extension,
please check PHP Configuration

i am sure the problem is that php 5 cannot recognise ,mysql server, or that in php 5 mysql server recognition isnt built in as default...one thing is for sure it should work fine but it isnt connecting to the mysql databse..before i upgraded i was getting the error message user not found...even though all the connection details were correct..this re itterates my point...php either cant connect or cant recognise mysql for some reason...any help would be appreciated
cheers
chris

Is libmysql.dll in your c:\windows directory?

Note: Windows users will need to enable php_mysql.dll inside of php.ini and either copy libmysql.dll into the Windows system directory, or make it available to the PATH. from: http://us4.php.net/mysql

yes i have enable php mysql in php.ini
also libmysql.dll is located in c:\windows
this is the error from the index.php (phpmyadmin)

cannot load mysql extension,
please check PHP Configuration
Documentation

aside from pulling hair out do i need to unninstall everything i can find on the system to do with php in order to install an earlier version of php? what version of php works best with mysql ? and which version of php works best with which version of mysql?
v frustrating
thanks in advance
ive tried all sorts of things to get this to work
seasrched 100s of sites and forums
maybe a complete re install is required with a compatable php/mysql config
rather than on a php version that requires a manual re config of all the guts
thanks in advance
chris

I'm not sure what to do at this point. Have you had a look at the IIs error logs to see if there is more information there?

If nothing else then I guess yes uninstall php completely and reinstall. Php 4 or 5 should work fine with mysql....

Dance

hi thanks for that
i went to get a drink and watched some tv..i did not touch th e pc at all..when i came back the phpmyadmin was working???? bizzare as before i left it it wasnt...no restart nothing...
anyway my loggin problem still exists
here is the code

 <?
  session_start();
  session_register("StudentID_session");
?>
<? // asp2php (vbscript) converted
?>
<? 
if (empty($_POST["EmailAddress"]))
{

//first time entering page

  $TheMessage="To sign in fill in your details below and click on the Teacher to enter.";
}
  else
{

//check that user exists and login is correct

// $conn is of type "adodb.connection"

$username = "chris";
$password = "astra123";
$hostname = "localhost";    
$dbh = @mysql_connect($hostname, $username, $password) 
    or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
$selected = @mysql_select_db("phptest",$dbh) 
    or die("Could not select phptest");
// you're going to do lots more here soon
mysql_close($dbh);

$RSStudent=$RSStudent_query=@mysql_query(("SELECT StudentID FROM mmstudents where StudentEmailAddress = '"
    .$_POST["EmailAddress"]."' and StudentPassword = '"
    .$_POST["Password"]."'"),$conn);  
$RSStudent=@mysql_fetch_array($RSStudent_query);
  if (($RSStudent==0))
  {

//invalid login

    [B]$TheMessage="Student not found. Re enter the correct email and password.";[/B]
  }
    else
  {

//valid entry

    $StudentID_session=$RSStudent["StudentID"];
    header("Location: "."student_menu.php");
  } 

} 

?>

when i enter correct login details the page returns with "connected to mysql" in the top left hand corner...however it also returns the message (in bold above) student not found!!! i have tripple checked the details ive entered are correct... yet it says they are not ie student not found.....
the page is acting as it was designed to ie if an incorrect detail is entered then the page returns on itself.. yet i am entering the correct email and password! the database servername password are all correct mysql server is running myphpadmin is working fine..test pages created with phpmyadmin on the database are working fine..i can add delete etc from the browser window...what seems to evade me is to connect to the database from the page code above....even though all the details are correct and working in other php pages..
bizzare
any help would be appreciated cheers
chris
the new and extreemly p/o php student

Don't call:

mysql_close($dbh);

until you have performed your querys.

Dance

i dont think thats the problem even when i remove that line
the page returns on itself and says user not found..i have an identical site on the same server written in asp it connects to the same database successfully...yet the php site says user not found.. im wondering if it is a location error or permission error ..it has to be something to do with either mysql or php...and the innability of this code to connect to the database...yet this cant be cos it says user not found..when in fact the user is in the database and returns the correct page in the asp site..it is only in the php version that it says user not found...seems illogical to me..
anyway i dont think im going to get to the bottom of it might be quicker to re write it all

Try removing the @s from all mysql_ commands. This will allow you to see any mysql or php erros.

Dance

lines 38 and 39 are in bold

// $conn is of type "adodb.connection"

$db_host = 'localhost';
$db_name = 'mildmaydemo';
$db_user = 'root';
$db_pass = 'astra123';
$pconn = 'off';

if($pconn == 'off') {
$db = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
} else {
$db = mysql_pconnect($db_host, $db_user, $db_pass) or die(mysql_error());
}
mysql_select_db($db_name, $db);


$RSStudent=$RSStudent_query=mysql_query(("SELECT StudentID FROM mmstudents where StudentEmailAddress = '"
.$_POST["EmailAddress"]."' and StudentPassword = '"
.$_POST["Password"]."'"),$conn);
$RSStudent=mysql_fetch_array($RSStudent_query);

if (($RSStudent==0))
{

the error message i get for these lines are :

Notice: Undefined variable: conn in C:\Inetpub\wwwroot\mildmayphp\index.php on line 38

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Inetpub\wwwroot\mildmayphp\index.php on line 38

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\mildmayphp\index.php on line 39


As you say removing the @ is a way to iron out ugly error messages...
thanks in advance
chris

$query = "SELECT Student ID FROM mmstudents where StudentsEmailAddress = {$_POST['EmailAddress']} and StudentPassword = {$_POST['Password']}";
$RSStudent_query=mysql_query($query,$db);
$RSStudent=mysql_fetch_array($RSStudent_query);

Try that instead. Hopefully I have no typos...

Dance

hi pasted the code in and got the same error in return ie:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\mildmayphp\index.php on line 38


line 38 is:

$RSStudent=mysql_fetch_array($RSStudent_query);

as i say i suspect that the problem is a permissions error or something. why i dont know it just seems that php is requiring something from the system that asp doesnt,, extra autentication? files to be in a certain place on the hard drive? there is a maze of info which makes it more confusing ..Im about to yell from the window.."Come Home asp all is forgiven"!
this is what i can do...
i can access the same mysql database from an asp page with the same username and password
i can access the same database from phpmyadmin edit updat delete etc
i can create new php pages from phpmyadmin which can open the database

but from this php page it always says user not found...even though the same validation passwords etc are used in the asp page which does open secessfully.. the php error message is the same
the error is illogical it is saying mysql cant find a user that is clearly there in the databse
why that is i dont know .

just a thought this is what i have

a test database (mysql) called mildmaydemo
the root user
a second user i created called chris
both have full privilages to the mildmaydemo database

iis 6
win 2003 server

php 5

php is woking fine ie myphpadmin etc

other pages i have created work fine on the same database with the same username and password..

$query = "SELECT Student ID FROM mmstudents where StudentsEmailAddress = {$_POST['EmailAddress']} and StudentPassword = {$_POST['Password']}";
$RSStudent_query=mysql_query($query,$db);
if (!$RSStudent_query) {
   $message  = 'Invalid query: ' . mysql_error() . "\n";
   $message .= 'Whole query: ' . $query;
   die($message);
}
$RSStudent=mysql_fetch_array($RSStudent_query);

Try that and see what it says...

Dance

it now gives this error


Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@hotmail.com and StudentPassword = astra123' at line 1 Whole query: SELECT Student ID FROM mmstudents where StudentEmailAddress = chris@hotmail.com and StudentPassword = astra123

Bah. I had typed Student ID instead of StudentID, don't know if you caught that or not. Anyways try the options below, or have you already got it working?

$query = "SELECT StudentID FROM mmstudents where StudentsEmailAddress = '{$_POST['EmailAddress']}' and StudentPassword = '{$_POST['Password']}'";

or:

$query = "SELECT StudentID FROM mmstudents where StudentsEmailAddress = " . "'" . "{$_POST['EmailAddress']}" . "'" . " and StudentPassword = " . "'" . "{$_POST['Password']}" . "'";

Dance

tried both of those edited the typos ie student instead of students ..now all the page does is posts back on itself..no error message...the code is designed to show the error message student not found...yet it doesnt it now just posts back onitself as if this was the first time entering the page..

very strange

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.