Page 1 of 1

problem to connect mysql local

PostPosted: 30. October 2013 15:58
by wduizer
Hy

I'm new in the world of scripting PHP, HTML and local hosting with Xampp, so i,m trying to learn a bit about it all.
I've created a form in php with and made the connection with the local mysql to save the input data in the table i've creted in myphpadmin:

<?php
$con=mysqli_connect("127.0.0.1","wduizer","q4MnayTwatX4yJQA","basic_web_development");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO waardes (naam, telnr, email)
VALUES
('$_POST[naam]','$_POST[telnr]','$_POST[email]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>

And then it won't go as planned.
I'll get the following message:
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'wduizer'@'localhost' (using password: YES) in G:\htdocs\vza-academy\basic_web_development\html_form_action.php on line 2
Failed to connect to MySQL: Access denied for user 'wduizer'@'localhost' (using password: YES)
Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in G:\htdocs\vza-academy\basic_web_development\html_form_action.php on line 13

Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in G:\htdocs\vza-academy\basic_web_development\html_form_action.php on line 15
Error:

please help....

Re: problem to connect mysql local

PostPosted: 30. October 2013 16:19
by wduizer
problem solved... the new user i applied didn't have the right rights.
Next question is now, how to set this right. I've connected with "root" without a password.

Re: problem to connect mysql local

PostPosted: 30. October 2013 18:00
by Altrea
How to create a new user with database specific priviledges

phpmyadmin -> Users -> Add User
fill in a username (wduizer), host dropdown field to local (so that the textfield is set to localhost), and twice times your password. Nothing more at this page (no permission ticks), just click the Go-button at the bottom of this page.

After that click on "edit permissions) of this new user
at the section "Database-specific privileges" select the database the user should get permissions to from the dropdown field.
tick the permissions the user should have (SELECT, INSERT, UPDATE are enough for many purposes) and click on the Go-Button of that specific section.
Thats all.