Jump to content

Recommended Posts

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 :)

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

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\">";



}
?>

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.

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\">";



}?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.