garydt Posted March 23, 2010 Share Posted March 23, 2010 mysql_select_db($database_newdb, $newdb); $query_Recordset5 = "SELECT * FROM counting"; $Recordset5 = mysql_query($query_Recordset5, $newdb) or die(mysql_error()); I'm getting- Warning: mysql_select_db() expects parameter 2 to be resource, null given in C:\xampp\xampp\htdocs\cag\index.php on line 7 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\xampp\htdocs\cag\index.php on line 9 What have I got wrong? Thanks. Link to comment https://forums.phpfreaks.com/topic/196223-cant-connect-to-database/ Share on other sites More sharing options...
dstar101 Posted March 23, 2010 Share Posted March 23, 2010 $newdb = mysql_connect_db(ADD, User, pass); mysql_select_db(dbname, $newdb); Link to comment https://forums.phpfreaks.com/topic/196223-cant-connect-to-database/#findComment-1030458 Share on other sites More sharing options...
garydt Posted March 23, 2010 Author Share Posted March 23, 2010 Now I'm getting- Fatal error: Call to undefined function mysql_connect_db() in C:\xampp\xampp\htdocs\cag\index.php on line 7 Link to comment https://forums.phpfreaks.com/topic/196223-cant-connect-to-database/#findComment-1030465 Share on other sites More sharing options...
dstar101 Posted March 23, 2010 Share Posted March 23, 2010 Oops sorry I mistyped it is mysql_connect(ADD,USER,PASS); Link to comment https://forums.phpfreaks.com/topic/196223-cant-connect-to-database/#findComment-1030485 Share on other sites More sharing options...
garydt Posted March 23, 2010 Author Share Posted March 23, 2010 I've put this now- mysql_connect("localhost","root"); mysql_select_db("people"); $query_Recordset5 = "SELECT * FROM newtable"; $Recordset5 = mysql_query($query_Recordset5, $gary) or die(mysql_error()); $result = mysql_query($query_Recordset5); $row_Recordset5 = mysql_fetch_assoc($Recordset5); $c = $row_Recordset5['visitor']; $c=$c+1; echo $c; $totalRows_Recordset5 = mysql_num_rows($Recordset5); I'm getting no errors now but I'm getting a blank page now. why? Link to comment https://forums.phpfreaks.com/topic/196223-cant-connect-to-database/#findComment-1030511 Share on other sites More sharing options...
MatthewJ Posted March 23, 2010 Share Posted March 23, 2010 $gary = mysql_connect("localhost","root") or die("Error connecting to database<br /><br />".mysql_error()); mysql_select_db("people") or die("Error selecting database<br /><br />".mysql_error()); $query_Recordset5 = "SELECT * FROM newtable"; $Recordset5 = mysql_query($query_Recordset5, $gary) or die("Error querying database<br /><br />".mysql_error()); $row_Recordset5 = mysql_fetch_assoc($Recordset5); $totalRows_Recordset5 = mysql_num_rows($Recordset5); do { $c = $row_Recordset5['visitor']; $c=$c+1; echo $c."br />"; } while($row_Recordset5 = mysql_fetch_assoc($Recordset5)); Give that a try... I saw you were providing the var $gary as a connection resource in the query but were not declaring it anywhere. I also assumed since you were using mysql_num_rows() that you were getting multiple results so I added the loop for the output. Link to comment https://forums.phpfreaks.com/topic/196223-cant-connect-to-database/#findComment-1030517 Share on other sites More sharing options...
Maq Posted March 23, 2010 Share Posted March 23, 2010 You may want to temporarily turn error reporting to max by adding these two lines directly after your opening php tag: ini_set ("display_errors", "1"); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/196223-cant-connect-to-database/#findComment-1030529 Share on other sites More sharing options...
garydt Posted March 23, 2010 Author Share Posted March 23, 2010 That works, thanks Link to comment https://forums.phpfreaks.com/topic/196223-cant-connect-to-database/#findComment-1030564 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.