Hi, guys! I have a programming question - I am very new to php and still a very retarded programmer _; I need some help with some code I hacked together ... it's probably the most deformed thing you'll ever see, but hey. Also, I replaced all the confidental components with capital entries 😉 The code is used in conjunction with a link on the previous page that picks up whatever ID it was given (depending on the link) and inserts the correct info into the HTML template.
So, the error message I keep getting is this:
Warning: Supplied argument is not a valid MySQL-Link resource in [path to the file was here] on line 104 ( the line of, "mysql_close($connection);")
The code:
<?php
// Connect to the database server
$dbcnx = @mysql_connect("localhost", "USER_NAME_HERE", "PASS");
if (!$dbcnx) {
echo( "<p>Unable to locate the database server - Damn! Pls try again a bit later. Thanks.</p>" );
exit ();
}
// Select the database
if (! @mysql_select_db("DATA_NAME") ) {
echo( "<p>Unable to locate the database server - Damn! Pls try again a bit later. Thanks.</p>" );
exit ();
}
?>
-some regular html here-
<?php
// generate and execute query
$query = "SELECT ID, Title FROM TABLE_NAME ORDER BY ID DESC";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
// if records present
if (mysql_num_rows($result) > 0)
{
// iterate through resultset
// print article titles
while($row = mysql_fetch_object($result))
{
?>
<a href="FILENAME.php?id=<? echo $row->ID; ?>"><?
echo $row->Title; ?></a>
<br>
<?
}
}
// if no records present
// display message
else
{
?>
<font size="-1">No info currently available</font>
<?
}
?>
- some more html comment here -
<?php
// generate and execute query
$query = "SELECT Title, Body, TheDate FROM TABLE_NAME WHERE id =
'$id'";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
// get resultset as object
$row = mysql_fetch_object($result);
// print details
if ($row)
{
?>
<br>
<center>
<? echo $row->Title; ?>
<br>
<? echo $row->TheDate; ?>
<br>
</center>
<p align=justify>
<? echo nl2br($row->Body); ?>
<br><br>
<a href="ANOTHER_FILE.php"><< Recent</a>
<?
}
else
{
?>
<p>
<font size="-1">That file could not be located in the
database. Whoops.</font>
<?
}
// close database connection
mysql_close($connection);
?>
So, can anyone help me straighten out what I'm sure is a fairly elementary error, (but not elementary enough for me)? Thanks! -Kate