Jump to content

Error when trying to submit into MySQL


JayCee

Recommended Posts

Hi,

 

I have created a simple HTML form and I'm trying to send the details to a MySQL DB when I click submit.  Once clicking submit from the HTML page I have created the following PHP page:

 

<?php

$Name = $_POST['FName'];

$Surname = $_POST['LName'];

$Comment = $_POST['Comment'];

$PName = $_POST['PFname'];

$PSurname = $_POST['PLname'];

$Year = $_POST['Year'];

$Contact = $_POST['Contact'];

$House = $_POST['HOuse'];

 

 

 

mysql_connect ("localhost","root","DBNAME") or die ('Error: ' . mysql_error());

mysql_select_db ("HOH");

 

$query="INSERT INTO entries (House, Name, Surname, Comment, Pupil_Name, Pupil_Surname, Year, Contact_No)VALUES ('".$House."','".$Name."','".$Surname."','".$Comment."''".$PName."','".$PSurname."','".$Year."','".$Contact."')";

 

mysql_query($query) or die (mysql_error());

 

ECHO "<meta http-equiv=\"refresh\" content=\"3; url=http:">";

 

?>

 

However when I click submit on my form page I get the following message.

 

Error: Access denied for user 'root'@'localhost' (using password: YES)

 

Do I need to define the password in order to access the MySQL database? Can I avoid this? Either way, how do I proceed?

 

Cheers,

 

JayCee

 

Link to comment
https://forums.phpfreaks.com/topic/187257-error-when-trying-to-submit-into-mysql/
Share on other sites

You are using mysql_connect() incorrectly. The parameters are:

 

mysql_connect (SERVER, USERNAME, PASSWORD)

 

You are apparently trying to pass the database name as the third parameter. You need to use mysql_select_db() after establishing the connection to select the database

You are using mysql_connect() incorrectly. The parameters are:

 

mysql_connect (SERVER, USERNAME, PASSWORD)

 

You are apparently trying to pass the database name as the third parameter. You need to use mysql_select_db() after establishing the connection to select the database

 

lol i didn't even read that. Too easy :)

the table is defined during the query:

 

$query="INSERT INTO entries (House, Name, Surname, Comment, Pupil_Name, Pupil_Surname, Year, Contact_No)VALUES ('".$House."','".$Name."','".$Surname."','".$Comment."''".$PName."','".$PSurname."','".$Year."','".$Contact."')";

 

The bold red part is your table name

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.