Jump to content

can't connect to database


garydt

Recommended Posts

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

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?

 

$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.

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.