简体   繁体   中英

Cannot establish connection to MySQL

I am new to server side programming but I know enough php to begin working with MySQL. So i made a phpMyAdmin account, made a database and a table in it. In dreamweaver i made a php file and connected it with the form as shown below.

HTML

<form action="phpinfo.php" method="POST">
    <input type="submit" id="submit_btn" value="Submit"/>
</form>

PHP

    <?php

$username="root";
$password="xxxxx";
$database="databaseABC";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

mysql_query($query);

$query = "INSERT INTO order VALUES ('','Shirt','M','black','that photo','L','none','UL','none','Sharpiee','#E0E0E0','BIU','Lobster','bottom','L')";

mysql_close();

?>

However on clicking the button browser is showing the following error.

Notice: Use of undefined constant localhost - assumed 'localhost' in C:\xampp\htdocs\college_ink\phpinfo.php on line 7

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\college_ink\phpinfo.php on line 7. Unable to select database

Please point out the error as this is my first time with server side programming?

You are using localhost as a variable where it should be a string.

Change it to the following:

mysql_connect("localhost",$username,$password);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM