emediastudios Posted November 11, 2007 Share Posted November 11, 2007 Hi all, having this problem where i get database not selected error. Could someone please tell me how to write the code to connect to my database and then insert this record below. My database called gcpropery. <?php mysql_query("INSERT INTO `employees` VALUES (NULL,'$name', '$rank', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')")or die (mysql_error()); ?> I'd be forever gratefull Quote Link to comment https://forums.phpfreaks.com/topic/76840-solved-database-connection-dramas-please-help/ Share on other sites More sharing options...
Foser Posted November 11, 2007 Share Posted November 11, 2007 What it seemed to happen is that your connecting to mysql, although you are not selecting your database. mysql_connect(localhost,username,password); mysql_select_db("gcpropery"); do you have that in your code? Quote Link to comment https://forums.phpfreaks.com/topic/76840-solved-database-connection-dramas-please-help/#findComment-389020 Share on other sites More sharing options...
emediastudios Posted November 11, 2007 Author Share Posted November 11, 2007 What it seemed to happen is that your connecting to mysql, although you are not selecting your database. mysql_connect(localhost,username,password); mysql_select_db("gcpropery"); do you have that in your code? I did as you said <?php // check if successfully copied if($copied == $uploadNeed) { //Writes the information to the database mysql_connect(localhost,root,5050888202); mysql_select_db("gcpropery"); mysql_query("INSERT INTO `employees` VALUES (NULL,'$name', '$rank', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')")or die (mysql_error()); print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">"; }?> and i get this error Lineup_020907_1024_200794104645.jpg valid ext Lineup_020907_1024_200794104645.jpg valid size No database selected Quote Link to comment https://forums.phpfreaks.com/topic/76840-solved-database-connection-dramas-please-help/#findComment-389023 Share on other sites More sharing options...
emediastudios Posted November 11, 2007 Author Share Posted November 11, 2007 Did a change and still get the same error, here is my new code <?php // check if successfully copied if($copied == $uploadNeed) { //Writes the information to the database mysql_connect("localhost","root","5050888202"); mysql_select_db("gcpropery"); mysql_query("INSERT INTO `employees` VALUES (NULL,'$name', '$rank', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')")or die (mysql_error()); print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/76840-solved-database-connection-dramas-please-help/#findComment-389025 Share on other sites More sharing options...
AndyB Posted November 11, 2007 Share Posted November 11, 2007 In http://www.phpfreaks.com/forums/index.php/topic,167156.msg736450.html#msg736450 you give a different name for (presumably) the same database. What's the real story here? Quote Link to comment https://forums.phpfreaks.com/topic/76840-solved-database-connection-dramas-please-help/#findComment-389027 Share on other sites More sharing options...
Foser Posted November 11, 2007 Share Posted November 11, 2007 your not showing the mysql names eg. mysql_query("INSERT INTO example (name, age) VALUES('Kyle', '29' ) ") Quote Link to comment https://forums.phpfreaks.com/topic/76840-solved-database-connection-dramas-please-help/#findComment-389030 Share on other sites More sharing options...
emediastudios Posted November 11, 2007 Author Share Posted November 11, 2007 In http://www.phpfreaks.com/forums/index.php/topic,167156.msg736450.html#msg736450 you give a different name for (presumably) the same database. What's the real story here? I have the site in three locations, my pc, my host, and my clients site on his host. Working on the one on my server for testing purposes, they are all the same, just differnt connection settings. Quote Link to comment https://forums.phpfreaks.com/topic/76840-solved-database-connection-dramas-please-help/#findComment-389031 Share on other sites More sharing options...
AndyB Posted November 11, 2007 Share Posted November 11, 2007 So on one the datanase name is gcpropery and on another it's gcproperty Quote Link to comment https://forums.phpfreaks.com/topic/76840-solved-database-connection-dramas-please-help/#findComment-389033 Share on other sites More sharing options...
emediastudios Posted November 11, 2007 Author Share Posted November 11, 2007 Well spotted thank you. fixed it up. seems i needed more than just the linked connection file <?php // check if successfully copied if($copied == $uploadNeed) { //Writes the information to the database $host="localhost"; // Host name $username="gcp13916"; // Mysql username $password="5emstudio23"; // Mysql password $db_name="gcp13916_gcproperty"; // Database name $tbl_name="employees"; // Table name mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_query("INSERT INTO `employees` VALUES (NULL,'$name', '$rank', '$suburb', '$price', '$content', '$content2','$agentmobile', '$agentemail','$uploadFile0','$uploadFile1', '$uploadFile2', '$uploadFile3', '$uploadFile4', '$uploadFile5', '$uploadFile6', '$uploadFile7', '$uploadFile8')")or die (mysql_error()); print "<meta http-equiv=\"refresh\" content=\"0;URL=property_added_successfully.php\">"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/76840-solved-database-connection-dramas-please-help/#findComment-389043 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.