Jump to content

Difficulty with accessing local MYSQL server with script.

- - - - -

  • Please log in to reply
4 replies to this topic

#1
april415

april415

    Newbie

  • Members
  • Pip
  • 6 posts
Hello,
Here is my difficulty that's aged me by fifty years. I am trying to write a script to insert table values into a table I have on my Windows MYSQL and then print out a confirmation page.
Here is my current effort :

<head> 

 <title> Aliens abducted me </title>


</head>


<body>


 <h2> Aliens Abducted Me- Report an Abduction</h2>



 <?php 

$when_it_happened=$_POST['whenithappened'];


$how_long=$_POST['howlong'];


$alien_description=$_POST['aliendescription'];


$fang_spotted=$_POST['fangspotted'];


$email=$_POST['email']; 


$dbc = mysqli_connect('localhost','root','  ','aliendatbase')

or die('Error connecting to MYSQL server');


$query = "INSERT INTO aliens_abduction (first_name, last_name, when_it_happened, how_long, " .

"how_many, alien_description, what_they_did, fang_spotted, other, email " .

 "VALUES ('$first_name', '$last_name', 'when_it_happened', '$how_long, '$how_many', " .

 "'$alien_description', '$what_they_did', '$fang_spotted', '$other', '$email')";

$result=mysqli_query($dbc,$query)

or die('error querying database.');

mysqli_close($dbc);

echo 'Thank you for submitting the form to the Dalek High Command.Prepare to be exterminated.<br />';


echo 'You where abducted  ' . $when_it_happened;


echo 'and were gone for  ' . $how_long.'<br />';


echo 'Describe them:  ' . $alien_description .'<br />';


echo 'Was Fang there ? ' . $fang_spotted .'<br />';


echo 'Your e-mail address is ' . $email;

?>


</body>


</html
what's not happening is the successful connection to my localhost MYSQL server.
I keep getting the message :

Quote

"Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\xampplite\htdocs\report1.php on line 24".

What I thought was happening was the user was incorrect, but after reading the server documentation it became clear to me that the user was "root" ,so I used root in the user parameter.Than I thought that maybe there was some confusion caused by including an empty password parameter, So I dropped the password parameter. But the error message is still insisting I am using a password.

I need is some kind soul, like you reading this post, to point out errors n my code and /or understanding of how MYSQL servers operate!:o
cheers and thanks,
April

Edited by Roger, 21 March 2011 - 04:03 PM.
added code block


#2
njr1489

njr1489

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
On this line:
$dbc = mysqli_connect('localhost', 'root', '  ', 'aliendatbase')
It doesn't seem like you specified a password on the third argument. Is that whitespace really your password? If you don't specify a password, then try and pass in null for the third argument. Also, try adding a fifth argument which would be the port number, whichever that number may be.

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Yes, by default on most AMP distributions the password should be null, just leave it out ('')
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
april415

april415

    Newbie

  • Members
  • Pip
  • 6 posts
Thank you both for your attention. I ended up creating a new user, which seemed to solve the trouble accessing the database;but it is helpful to know in the future that a empty password on a amp installation is also effective!
take care and cheers
April

#5
april415

april415

    Newbie

  • Members
  • Pip
  • 6 posts
Alright, I have set up a new user and still no success and the same **** error message.
In order to get to the solution , I have to make sure that these users have the privileges that they seem to have or I need to be able to remedy if not. There still might be code problems , but I think changing something in MYSQL will go the longest way. Let's here from the MYSQL jockeys that have encountered this error before!

Again thanks for the help you two,you both helped me narrow down possible coding mistakes as well as really focus my problem down to a MYSQL server issue.
cheers
April




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users