Jump to content

Recommended Posts

I'm getting the error "cannot select from db:  'MY_db'".  i suspect one of two things.  either it's not connecting for some reason, and it's just not err'ing on not connecting b/c i didn't code for an error message, or the mysql version (4) wants my db name a different way. 

 

the db is on godaddy.com - so the full path to the server is:

mydb.db.(a bunch of numbers).hostedresource.com

for the db name i have typed only the 'MY_db' portion.  i have also successfully logged into the db using phpmyadmin, and have checked and re-checked the $conn function making sure I have the right credentials. 

 

HELP!  here's my simpleton code...

 

<?php

$athleteid = $_POST['name'];

$conn = mysql_connect("MY_DB", "username",

"password");

if (!$conn)

{

  die('Could not connect: ' . mysql_error());

}

$select = mysql_select_db(("MY_db"), $conn);

if (!$select);

{

  die('could not select db: MY_db ' . mysql_error());

}

$Ins = mysql_query("INSERT INTO tbathletepics (AthleteID) VALUES ('$athleteid')");

if ($Ins);

echo "your data has been posted, testing complete..";

{

  die('your data was not posted. ' . mysql_error());

}

$id = mysql_query("SELECT * FROM athletepics");

while($row = mysql_fetch_array($id))

{

echo $row['AthleteID'];

echo "<br />";

}

mysql_close($conn);

?>

mysql_connect

 

The first parameter should be the host, not the db. The DB comes when using mysql_select_db

 

Since it looks like you are trying to define the database name inside the connect, that is why I posted it. If your code does indeed have the server. Please disregard.

 

A side note:

$select = mysql_select_db(("MY_db"), $conn);
// should be
$select = mysql_select_db("MY_db", $conn);

 

As that may also effect it.

To me it looks like he is connecting to the server ok, but the user he is logging under doesnt have the credentials to access the specific db.

 

If the server is a shared server, some like to add a prefix to table names. so ya have to watch out for that as well. Check under yer Control panel, MySQL section, u should have a PHPMyAdmin tool or similar, to look at the table/field names u do have access to.

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.