JayCee Posted January 5, 2010 Share Posted January 5, 2010 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 Quote Link to comment Share on other sites More sharing options...
aeroswat Posted January 5, 2010 Share Posted January 5, 2010 Are you certain that localhost is the server you are supposed to be connecting to? Is this on your own machine or a remotely hosted server? Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 5, 2010 Share Posted January 5, 2010 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 Quote Link to comment Share on other sites More sharing options...
JayCee Posted January 5, 2010 Author Share Posted January 5, 2010 remotely.....Am I being dumb? Quote Link to comment Share on other sites More sharing options...
RaythMistwalker Posted January 5, 2010 Share Posted January 5, 2010 yes you do need the password: mysql_connect ("localhost","username","password") or die ('Error: ' . mysql_error()); mysql_select_db ("HOH"); Quote Link to comment Share on other sites More sharing options...
JayCee Posted January 5, 2010 Author Share Posted January 5, 2010 OMG...You're right, totally missed it. Been working on this for ages, think I may need to give my eyes and my brain a rest!!! Quote Link to comment Share on other sites More sharing options...
aeroswat Posted January 5, 2010 Share Posted January 5, 2010 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 Quote Link to comment Share on other sites More sharing options...
JayCee Posted January 5, 2010 Author Share Posted January 5, 2010 Do I define my Table here after defining the DB mysql_select_db ("HOH"); Should it be something like mysql_select_db ("HOH", "Table"); Quote Link to comment Share on other sites More sharing options...
RaythMistwalker Posted January 5, 2010 Share Posted January 5, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.