Lee-Bartlett Posted September 11, 2008 Share Posted September 11, 2008 Ok im a novice and all i wanna do i echo back some of my rows in my database so heres the code, i am getting a """"Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\database.php on line 23 database query failed: """"" <?php $db_host = "localhost"; // Your database host server, eg. db.server.com $db_user = "removed"; // User who has access to the database $db_pass = "removed"; // User password to access database $db_name = "removed"; // Existing database name // -- Connecting to the database (not persistent connection) $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db) or die(mysql_error()); ?> <html> <head> </head> <body> <?php $result = mysql_query("SELECT * FROM subjects", $connect); (on this line here) if (!$result) { die("database query failed: " . mysql_error()); } while ($row = mysql_fetch_array($result)) { echo $row[1]." ".$row[2]."<br />"; } ?> </body> </html> <?php mysql_close($connect); ?> can anyone help me out please Link to comment https://forums.phpfreaks.com/topic/123774-simple-connection-to-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 11, 2008 Share Posted September 11, 2008 supplied argument is not a valid MySQL-Link resourceSo did you read the error message and look at your code to find out why the the MySQL-Link resource might not be valid? Where is $connect being set in your code? What variable name are you setting from the mysql_connect() statement? Link to comment https://forums.phpfreaks.com/topic/123774-simple-connection-to-database/#findComment-639124 Share on other sites More sharing options...
KevinM1 Posted September 11, 2008 Share Posted September 11, 2008 Ok im a novice and all i wanna do i echo back some of my rows in my database so heres the code, i am getting a """"Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\database.php on line 23 database query failed: """"" <?php $db_host = "localhost"; // Your database host server, eg. db.server.com $db_user = "removed"; // User who has access to the database $db_pass = "removed"; // User password to access database $db_name = "removed"; // Existing database name // -- Connecting to the database (not persistent connection) $db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$db) or die(mysql_error()); ?> <html> <head> </head> <body> <?php $result = mysql_query("SELECT * FROM subjects", $connect); (on this line here) if (!$result) { die("database query failed: " . mysql_error()); } while ($row = mysql_fetch_array($result)) { echo $row[1]." ".$row[2]."<br />"; } ?> </body> </html> <?php mysql_close($connect); ?> can anyone help me out please You don't have anything within the variable $connect. Replace all instances of it with $db, the variable you assigned to with your mysql_connect() function call. Link to comment https://forums.phpfreaks.com/topic/123774-simple-connection-to-database/#findComment-639130 Share on other sites More sharing options...
revraz Posted September 11, 2008 Share Posted September 11, 2008 Or just remove it. Link to comment https://forums.phpfreaks.com/topic/123774-simple-connection-to-database/#findComment-639132 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.