So, I just installed XAMPP on my PC running Windows 7. Here's what my website looks like:

/Header.php

<?php
session_start();
include("http://localhost/Functions.php");
connect();
?>

/Functions.php

<?php
function connect(){
$username = "dartz654";
$password = "letmein";
$hostname = "localhost";
$con = mysql_connect($hostname,$username,$password) or die ("Unable to connect");
mysql_select_db(database, $con);
}
?>

/My/Register.php

<?php
include("http://localhost/Header.php");

if(!$_POST['submit']){
    echo "<form method=\"post\">";
    echo "<input type=\"text\" name=\"username\">";
    echo "<input type=\"password\" name=\"password\">";
    echo "<input type=\"submit\" name=\"submit\" value=\"Register\">";
    echo "</form>";
}else {

$username = $_POST['username'];
$password = $_POST['password'];

$sql = "INSERT INTO `users` (`username`,`password`) VALUES ('".$username."','".$password."')";
$res = mysql_query($sql) or die(mysql_error());

echo "You've registered.";
}

?>

When I hit 'register' on the register one, it'll show an error like this:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\My\Register.php on line 15

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\My\Register.php on line 15
Access denied for user 'ODBC'@'localhost' (using password: NO)

Help please?

P.S. If theres some error in my code, its probably just a mistake I made when cutting out code... The actual register is alot longer, I just took out the unimportant stuff. The real problem is the connection part...

Recommended Answers

All 5 Replies

In line 7 of /Functions.php in your post you put:

mysql_select_db(database, $con);

In this context the keyword database is neither a name or a variable. Perhaps you meant "database" or $database when you typed it?

In my connect function I use the name of my database there:

mysql_select_db('ecusersdb',$con);

Yes, "database" is the name of the database. Do i have to put the ' around it?

Yes. If you don't put either single or double quotes around it PHP will treat it as a keyword/function and not as a name.

each in every page the connection must there.
example you create a connet.php containing
mysql_connect('localhost','root','');
then include connect.php in every page.

if we look at table user :

 Select * From mysql.user;

nothing user with name 'ODBC'
but, default user to use ODBC.
i also don't know why ?

but, you can try to make user ODBC.
and then
try to given access table to user :

 grant all On [db].[tabelName] to [userName];

example

 grant all On mysql.* to root;
 grant all On mysql.* to ODBC;
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.