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 Link to comment https://forums.phpfreaks.com/topic/187257-error-when-trying-to-submit-into-mysql/ 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? Link to comment https://forums.phpfreaks.com/topic/187257-error-when-trying-to-submit-into-mysql/#findComment-988855 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 Link to comment https://forums.phpfreaks.com/topic/187257-error-when-trying-to-submit-into-mysql/#findComment-988859 Share on other sites More sharing options...
JayCee Posted January 5, 2010 Author Share Posted January 5, 2010 remotely.....Am I being dumb? Link to comment https://forums.phpfreaks.com/topic/187257-error-when-trying-to-submit-into-mysql/#findComment-988860 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"); Link to comment https://forums.phpfreaks.com/topic/187257-error-when-trying-to-submit-into-mysql/#findComment-988861 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!!! Link to comment https://forums.phpfreaks.com/topic/187257-error-when-trying-to-submit-into-mysql/#findComment-988862 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 Link to comment https://forums.phpfreaks.com/topic/187257-error-when-trying-to-submit-into-mysql/#findComment-988866 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"); Link to comment https://forums.phpfreaks.com/topic/187257-error-when-trying-to-submit-into-mysql/#findComment-988875 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 Link to comment https://forums.phpfreaks.com/topic/187257-error-when-trying-to-submit-into-mysql/#findComment-988903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.