MySQL Error

  • ben_sigma
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: South Australia

Post 3+ Months Ago

Hi Again all,

I was passed this error from my page and cant figure out the problem.
Any Ideas?

Code: [ Select ]
Warning: mysql_close(): 12 is not a valid MySQL-Link resource in C:\xampp\htdocs\bluehole\includes\firefox\localevent\localeventscript.php on line 31


I checked line 31 and this is the code on that line:
Code: [ Select ]
mysql_close($con);


Once again Help is appreciated :D
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

What is $con?
  • ben_sigma
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: South Australia

Post 3+ Months Ago

$con is just the name of the connection to the database.
  • ben_sigma
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: South Australia

Post 3+ Months Ago

This is the full code.
Code: [ Select ]
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("blue_users", $con);
$result = mysql_query("SELECT * FROM events");

echo "<table id='eventstable'>";
echo "<tr style='width: 100%;'><th id='etth'>By</th> <th id='etth'>Date</th> <th id='etth' style='width: 120px;'>Title</th></tr>";
while($row = mysql_fetch_array($result))
    {
    $set = mysql_connect("localhost","root","");
    if (!$set)
        {
        die('Could not connect: ' . mysql_error());
        }
    mysql_select_db("blue_users", $set);
    $result2 = mysql_query("SELECT * FROM user_details WHERE id='".$row['postedby']."'");
    while($row2 = mysql_fetch_array($result2))
        {
        echo "<tr><td>".$row2['DisplayName']."</td>";
        }
    mysql_close($set);
    echo "<td>".$row['date']."</td><td>".$row['title']."</td></tr>";
    }
echo "</table>";
mysql_close($con);
?>
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7. mysql_select_db("blue_users", $con);
  8. $result = mysql_query("SELECT * FROM events");
  9. echo "<table id='eventstable'>";
  10. echo "<tr style='width: 100%;'><th id='etth'>By</th> <th id='etth'>Date</th> <th id='etth' style='width: 120px;'>Title</th></tr>";
  11. while($row = mysql_fetch_array($result))
  12.     {
  13.     $set = mysql_connect("localhost","root","");
  14.     if (!$set)
  15.         {
  16.         die('Could not connect: ' . mysql_error());
  17.         }
  18.     mysql_select_db("blue_users", $set);
  19.     $result2 = mysql_query("SELECT * FROM user_details WHERE id='".$row['postedby']."'");
  20.     while($row2 = mysql_fetch_array($result2))
  21.         {
  22.         echo "<tr><td>".$row2['DisplayName']."</td>";
  23.         }
  24.     mysql_close($set);
  25.     echo "<td>".$row['date']."</td><td>".$row['title']."</td></tr>";
  26.     }
  27. echo "</table>";
  28. mysql_close($con);
  29. ?>
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

I don't know about the error, but you could make that query into one instead of two it seems to me ... something like ...
Code: [ Select ]
SELECT * FROM events LEFT JOIN user_details ON events.postedby = user_details.id

that way you don't have to open the connection so many times, only once ... and then the error wouldn't be there anyway I'm sure ... I know this isn't exactly the solution that you wanted, but I think this way is better ...
  • ben_sigma
  • Beginner
  • Beginner
  • User avatar
  • Posts: 58
  • Loc: South Australia

Post 3+ Months Ago

hey thanks heaps i changed my script and it works perfectly.

Appreciated
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

excellent. I'm glad I could've helped you ...

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 150 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.