karnegyhall Posted April 20, 2009 Share Posted April 20, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/154915-im-a-newbie-having-a-problem-with-mysql-select/ Share on other sites More sharing options...
premiso Posted April 20, 2009 Share Posted April 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/154915-im-a-newbie-having-a-problem-with-mysql-select/#findComment-814827 Share on other sites More sharing options...
laffin Posted April 20, 2009 Share Posted April 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/154915-im-a-newbie-having-a-problem-with-mysql-select/#findComment-814919 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.