divz2 Posted October 14, 2009 Report Share Posted October 14, 2009 Hi, I am trying to write code for an online form in php and mysql so that the form information will be collected in a database in phpmyadmin. The code is working locally (when I use localhost) but it is not working online when I upload the form onto my website. Can you please tell me what the problem is? Thank you very much. Form php code: $name = $_POST['name']; $company = $_POST['company']; $phone = $_POST['phone']; $email = $_POST['email']; $address = $_POST['address']; mysql_connect("localhost", "root", "my_password") or die('Error: '.mysql_error()); mysql_select_db("olympic_support"); $query="INSERT INTO reseller_pack (name,company,phone,email,address) VALUES ('$_POST[name]','$_POST[company]','$_POST[phone]','$_POST[email]','$_POST[address]')"; mysql_query($query) or die('Error updating database'); echo "Database updated"; When I try to run the page on my website, I am getting the following error: Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in /home/exquip/www/olympicsupport.com/resellerform.php on line 63 Error: Access denied for user 'root'@'localhost' (using password: YES) Quote Link to comment Share on other sites More sharing options...
falkencreative Posted October 14, 2009 Report Share Posted October 14, 2009 Your issue is exactly what the error message is telling you... you have your username or password incorrect. Make sure your database is set up correctly, and that you are using the correct username/password to access it. Also, remember to never trust input from the user. You really should be checking to make sure the user hasn't passed any invalid/malicious data into your form. At the very least, you should be using something like htmlspecialchars() (http://php.net/manual/en/function.htmlspecialchars.php) to help protect yourself. Quote Link to comment Share on other sites More sharing options...
divz2 Posted October 14, 2009 Author Report Share Posted October 14, 2009 Thank you for your reply. It might be a silly question but how is the form working on localhost if the username and password are wrong? Am I missing something basic? It is updating the database in phpmyadmin when I run the form on localhost but giving error after uploading the form onto my website. Any help is very much appreciated. Thanks. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted October 14, 2009 Report Share Posted October 14, 2009 how is the form working on localhost if the username and password are wrong? It's working on localhost because it is using the correct username/password for your local database setup. Your usernames/passwords for your local machine and your web hosting will be different. I would highly doubt that your hosting gives you a database username of "root". Quote Link to comment Share on other sites More sharing options...
divz2 Posted October 15, 2009 Author Report Share Posted October 15, 2009 So will the user details be the same as the login details that I use to connect to my website using ftp?? If not, then where will I find the username and password for this code to work? Thanks a lot. Quote Link to comment Share on other sites More sharing options...
divz2 Posted October 15, 2009 Author Report Share Posted October 15, 2009 I am trying to collect data entered on my website (in php) into the sql databases and tables located on my local phpmyadmin. Or is there any other correct procedure to collect online form data? Can anyone please let me know what is the procedure to do this. Thank you. Quote Link to comment Share on other sites More sharing options...
Wickham Posted October 15, 2009 Report Share Posted October 15, 2009 If you want to update the database on your local machine, then you can get the web page form to feed the database on your host's server as it normally would, then export to your own computer's database (manually, I don't know if it can be automated). If you set up your own computer as the host, then of course the form data will go straight into your computer's database, but I have no idea how to do this and you would no doubt have to set up special arrangements with your ISP because of all the traffic. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted October 15, 2009 Report Share Posted October 15, 2009 So will the user details be the same as the login details that I use to connect to my website using ftp?? If not, then where will I find the username and password for this code to work?Thanks a lot. Ah, I see your confusion. No, you won't be able to use a form on your website to connect to your database on your local computer (unless your local computer is a server and is always connected to the internet). You'll need to create a database on your hosting (usually done through your hosting control panel) and have all the form data stored there. If you want it accessible on your local machine, you'll have to export it from your online database and import it on your local machine (most likely using the Import/Export feature of PHPMyAdmin) Quote Link to comment Share on other sites More sharing options...
divz2 Posted October 16, 2009 Author Report Share Posted October 16, 2009 Hi, Thank you once again for all your replies. I am still struggling with the forms and databases... How do I create a database on my host? (My website is currenly hosted by a company called Verio). I checked the control panel for the website but I cannot seem to find any database creation tool on it. Is there any other method to create a database for an online form? Sorry about these basic questions - I am new to all this php/mysql so struggling with the concepts. Also are there any tutorials that can show the step by step process. Thanks a lot. Quote Link to comment Share on other sites More sharing options...
Wickham Posted October 16, 2009 Report Share Posted October 16, 2009 It looks as if you may need to change your hosting service. Check the emails or letters you got when you signed up; it should mention how many email addresses, domain names, sub-domains, parked domains, databases (if any), upload/download limits it allows and also programs like PHP that it supports. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted October 16, 2009 Report Share Posted October 16, 2009 I took a glance at the Verio website, and I'm not seeing any plans that don't have database support. If you can't find it on your own, perhaps it's something to contact your hosting support about. You may want to take a look at this article by Verio: http://support.verio.com/documents/view_article.cfm?doc_id=4024 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.
Note: Your post will require moderator approval before it will be visible.