fbm Posted February 23, 2009 Share Posted February 23, 2009 Hi I am trying to submit some very simple data to my DB but it returns an error saying no DB selected. my submit page is simple <form name="form" method="POST" action="?page=processclient"> <input name="client_name" type="text" value="client name" /> <input name="client_email" type="text" value="client email" /> <input name="add" type="submit"/> </form> it gets passed to processclient.php which looks like this <?php include "includes/config.php"; $client_name = $_POST['client_name']; $client_email = $_POST['client_email']; $query = "INSERT INTO `clients`(`client_name`,`client_email`)VALUES('".$client_name."','".$client_email."')"; mysql_query($query) or die(mysql_error()); echo "<center>"; echo "Please Wait ... Client being added"; echo "<META HTTP-EQUIV=Refresh CONTENT='5; URL=?page=manage'> "; echo "</center>"; ?> and my config file looks like this <?php $dbhost = "localhost"; $dbname = "hidden"; $dbuser = "hidden"; $dbpass = "hidden"; //connect to MySQL database $db = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db("$dbname",$db); ?> I have removed my DB login details, i'm sure i get connected to the DB as i don't get an error saying cant connect. I'm new to PHP but have a few years HTML/CSS knowledge so be easy in your response if its something sillly Any ideas? Cheers Link to comment https://forums.phpfreaks.com/topic/146593-solved-submitting-data-but-getting-error-no-database-selected/ Share on other sites More sharing options...
Julian Posted February 23, 2009 Share Posted February 23, 2009 Hello, Had you tried without quoting the $dbname As follows: //connect to MySQL database $db = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($dbname,$db); Link to comment https://forums.phpfreaks.com/topic/146593-solved-submitting-data-but-getting-error-no-database-selected/#findComment-769571 Share on other sites More sharing options...
The Little Guy Posted February 23, 2009 Share Posted February 23, 2009 Make sure this value is 100% correct, also it is case sensitive: $dbname = "hidden"; This should work: $dbHost = "localhost"; //Location Of Database usually its localhost $dbUser = "xxxx"; //Database User Name $dbPass = "xxxx"; //Database Password $dbDatabase = "xxxx"; //Database Name $db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database."); mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database."); Link to comment https://forums.phpfreaks.com/topic/146593-solved-submitting-data-but-getting-error-no-database-selected/#findComment-769573 Share on other sites More sharing options...
trq Posted February 23, 2009 Share Posted February 23, 2009 Your form action is wrong. <form name="form" method="POST" action="?page=processclient"> should be.... <form name="form" method="POST" action="processclient.php"> Link to comment https://forums.phpfreaks.com/topic/146593-solved-submitting-data-but-getting-error-no-database-selected/#findComment-769574 Share on other sites More sharing options...
The Little Guy Posted February 23, 2009 Share Posted February 23, 2009 Your form action is wrong. <form name="form" method="POST" action="?page=processclient"> should be.... <form name="form" method="POST" action="processclient.php"> I don't think there is anything wrong with that... Link to comment https://forums.phpfreaks.com/topic/146593-solved-submitting-data-but-getting-error-no-database-selected/#findComment-769575 Share on other sites More sharing options...
trq Posted February 23, 2009 Share Posted February 23, 2009 Your form action is wrong. <form name="form" method="POST" action="?page=processclient"> should be.... <form name="form" method="POST" action="processclient.php"> I don't think there is anything wrong with that... The first action will post to the same page. The op states he is passing the form to processclient.php. Link to comment https://forums.phpfreaks.com/topic/146593-solved-submitting-data-but-getting-error-no-database-selected/#findComment-769578 Share on other sites More sharing options...
The Little Guy Posted February 23, 2009 Share Posted February 23, 2009 Your form action is wrong. <form name="form" method="POST" action="?page=processclient"> should be.... <form name="form" method="POST" action="processclient.php"> I don't think there is anything wrong with that... The first action will post to the same page. The op states he is passing the form to processclient.php. ah... didn't read that but it still could work if he was on processclient.php, and just have it post back to it's self, he never specified what page the form was on... Link to comment https://forums.phpfreaks.com/topic/146593-solved-submitting-data-but-getting-error-no-database-selected/#findComment-769583 Share on other sites More sharing options...
fbm Posted February 23, 2009 Author Share Posted February 23, 2009 WOW 3 fast responses. I checked over my code and all was lookign good against your comments so i checked my DB and silly me mispelt the DB name in PMA so corrected that and all workign fine now As for the comments about the form action beign correct or not, I am using a variable for my page links and the action i had in my code does post correctly not sure how it all works lol just getting code from tutorials and guides on teh web and putting it all together Thanks guys, working now. How do i changed the forum post to solved? im new here Link to comment https://forums.phpfreaks.com/topic/146593-solved-submitting-data-but-getting-error-no-database-selected/#findComment-769585 Share on other sites More sharing options...
trq Posted February 23, 2009 Share Posted February 23, 2009 How do i changed the forum post to solved? im new here Bottom left corner. I'll get it for now. Link to comment https://forums.phpfreaks.com/topic/146593-solved-submitting-data-but-getting-error-no-database-selected/#findComment-769623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.