Jump to content

Recommended Posts

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

supplied argument is not a valid MySQL-Link resource
So 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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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