Jump to content

Database select problem


mr_badger

Recommended Posts

I'am getting this error on one of my pages "Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in".

this is the code

<?php require_once('../Connections/conn.php'); ?>
<?php
mysql_select_db($database_web78-salon, $web78-salon);
$query_rsTimes = "SELECT DISTINCT availDate FROM savailability ORDER BY availDate ASC";
$rsTimes = mysql_query($query_rsTimes, $web78-salon) or die(mysql_error());
$row_rsTimes = mysql_fetch_assoc($rsTimes);
$totalRows_rsTimes = mysql_num_rows($rsTimes);
?>

Link to comment
https://forums.phpfreaks.com/topic/53332-database-select-problem/
Share on other sites

I have tried what you suggested and the errors have gone, but it says no database selected, I can't work out why it's saying this.

<?php
$db_name = web78-salon;
$db_user = web78-salon;
mysql_select_db("localhost,web78-salon,darwen");
$query_rsTimes = "SELECT DISTINCT availDate FROM savailability ORDER BY availDate ASC";
$rsTimes = mysql_query($query_rsTimes, $conn) or die(mysql_error());
$row_rsTimes = mysql_fetch_assoc($rsTimes);
$totalRows_rsTimes = mysql_num_rows($rsTimes);
?>

Take a much closer look at my suggestion.  The variables I defined are strings, hence their definition within quotes.  The db_select query uses variables, not something enclosed in quotes as a single variable.

 

I'm skeptical that your database name and username are identical, but you should know what's what.

 

I'd suggest you move the definitions of host, database name, database user, database password, etc. into an included file (like connections.php perhaps) and make sure you define them as strings, and then in your script always refer to those defined variable names.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.