Click to See Complete Forum and Search --> : Can't connect mysql server!


light85
January 13th, 2005, 06:37 AM
Hi, i have a login page:



<html>
<head>
<title>Welcome to ET0023 Login</title>
</head>

<form name="form1" method="post" action="login.php">
<table width="75%" border="0">
<tr>
<td width="23%">Your Username:</td>
<td width="77%"><input name="username2" type="text" id="username23"></td>
</tr>
<tr>
<td height="31">Your Password:</td>
<td><input name="password2" type="password" id="password23"></td>
</tr>
</table>
<p>
<input type="submit" name="Submit2" value="Log In">
</p>
</form>
</body>
</html>


login.php

<?
$username=$_POST['username2'];
$password=$_POST['password2'];
$db = mysql_connect("localhost", "root", "hsienhwee") or die ('My SQL Error: ' . mysql_error());
mysql_select_db("people",$db);
$stuff = mysql_query("SELECT * FROM `users` WHERE Username='".$username."' AND password='".$password."'") or die("MySQL Login Error: ".mysql_error());
if (mysql_num_rows($stuff) > 0) {
$row=mysql_num_rows($stuff);
echo "You have logged in as $username <br>";
} else {
echo("Login Incorrect. Please Try Again!");
}
?>


and after i enter the username and password and submit, i got this error:
Fatal error: Call to undefined function mysql_connect() in c:\Inetpub\wwwroot\test\login.php on line 4

What went wrong? Thanks in advance for any help given.

khp
January 13th, 2005, 07:45 AM
You probably don't have mysql enabled in your php installation.

Read http://www.php.net/manual/en/ref.mysql.php

Firewireguy
January 20th, 2005, 08:20 AM
ignore me.

khp
January 20th, 2005, 08:53 AM
I' don't think that it's that mysql isn't installed, after all the call to mysql_connect() on line 3 is not throwing the error.


Ehh, what are you talking about ???
By my count line 3 is
$password=$_POST['password2'];
Of course there is no way for me to be sure, there could be some whitespace light85 didn't post.
Anyways there is only one call to mysql_connect, the one on line 4, which corresponds very well with the error message.

And of course light85's use mysql_connect, is quite correct. See http://www.php.net/mysql_connect .

Nibinaear
January 23rd, 2005, 05:33 AM
Why not just use odbc_connect(localhost,user,password) ?