I am learning PHP and MySQL through tutorials, and now i am stucked at a point. In this i have to access my database using created php file, but after running error occurs,
SQL error: Access denied for user ‘’@‘localhost’ (using password: NO)
This means i am not providing username and password, but i dont know how do i provide it through php file ? Please help
Code :
******* form.php **********
<form method="post" action="user.php">
<p><b>User ID:</b> <input type="text" name="userid" /></p>
<p><input type="submit" value="Search" /></p>
</form>
--------------------------------------…
********* User.php ************
<?php
import_request_variables("pg", "form_");
$db = mysql_connect("localhost:/export/mysql/mysql.sock");
mysql_select_db("forum", $db);
$sql = "SELECT name, email"
. " FROM Users"
. " WHERE userid = '$form_userid'";
$rows = mysql_query($sql, $db);
if(!$rows) {
$error = "SQL error: " . mysql_error();
} elseif(mysql_num_rows($rows) == 0) {
$error = "No such user name found";
} else {
$error = FALSE;
$user_name = mysql_result($rows, 0, 0);
$user_email = mysql_result($rows, 0, 1);
}
?>
<html>
<head>
<title>User information</title>
</head>
<body>
<?php
if($error) {
echo "<h1>Error accessing user information</h1>\
";
echo "<p>$error</p>\
";
} else {
echo "<h1>Information about $form_userid</h1>\
";
echo "<p>User ID: <tt>$form_userid</tt></p>\
";
echo "<p>Real name: $user_name</p>\
";
echo "<p>E-mail address: <tt>$user_email</tt></p>\
";
}
?>
</body>
</html>