Re: mysql error

From: Date: Fri, 17 May 2002 17:52:14 +0000
Subject: Re: mysql error
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-98146@lists.php.net to get a copy of this message
The mysql_select_db() function is going to return a handle. You need to capture that handle and use it as the second parameter in your mysql_query() function. Although this is not required in certain cases where the server automatically knows which database to work with, chances are thats whats giving you the error. Use like this.. $db = mysql_select_db(); mysql_query($query, $db); -Kevin ----- Original Message ----- From: "Randum Ian" <ian@danceportal.co.uk> To: "PHP" <php-general@lists.php.net> Sent: Friday, May 17, 2002 11:45 AM Subject: [PHP] mysql error > Hi all, > > I have got this code but I can get it to work, it doesnt make sense! > > <snip> > <?php > > $host="localhost"; > $username="user"; > $password="pass"; > $database="admin"; > > $mysqlconnect = mysql_connect($host, $username, $password) or die ("Cannot > connect to mySQL server, check it is running"); > > mysql_select_db($database, $mysqlconnect) or die ("Cannot connect to the > database, check it is set right"); > > $result = mysql_query("SELECT * FROM user"); > > $count = mysql_num_rows($result); > > $counted = number_format($count); > > echo $counted; > > ?> > <snip> > > but I am getting this error - "Warning: Supplied argument is not a valid > MySQL result resource in /usr/home/e/a/eagadmin/public_html/main.php on line > 14" but I dont understand why! > > Can anyone help? > > Regards, Ian. > --- > Randum Ian > DJ / Reviewer / Webmaster, DancePortal (UK) Limited > ian@danceportal.co.uk > http://www.danceportal.co.uk > DancePortal.co.uk - Global dance music media > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#98146) next »