Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post

    Multiple Error in code

    I get the following error in the code below

    "Connected successfully to tableconnected to database:
    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /hermes/bosweb/web251/b2510/ipw.cypressp/public_html/counter.php on line 28
    Error creating database: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #3' at line 1
    Warning: setcookie() expects parameter 2 to be string, resource given in /hermes/bosweb/web251/b2510/ipw.cypressp/public_html/counter.php on line 36
    Array ( ) Welcome guest!"

    Code:
    <?php
    
    // connect to mysql
    $link = mysql_connect('localhost', 'db', 'password'); 
    if (!$link) { 
        die('Could not connect: ' . mysql_error()); 
    } 
    else {
    echo 'Connected successfully to table'; 
    }
    
    
    // select database
    $db_selected = mysql_select_db('table', $link);
    
    if (!$db_selected)
     {
        die('Not connected : ' . mysql_error());
    }
    else 
    {
    echo 'connected to database: '; 
    }
    $query = mysql_query("SELECT counter FROM stats WHERE id=1, $link"); 
    $results = mysql_query($query, $link);
    echo $results;
    if (mysql_query($link,$results))
      {
      echo "Database my_db created";
      }
    else
      {
      echo "Error creating database: " . mysql_error();
      }
    setcookie("TestCookie", $query, time()+3600);  /* expire in 1 hour */
    
    while($row=mysql_fetch_assoc($query)) {
    $stats=$row['counter']; } 
    
    echo $counted;
    
    
    // Print a cookie
    echo $_COOKIE["testcookie"];
    
    // A way to view all cookies
    print_r($_COOKIE);
    
    if (isset($_COOKIE["Testcookie"]))
      echo "Welcome " . $_COOKIE["TestCookie"] . "!<br />";
    else
      echo "Welcome guest!<br />";
    ?>
    Can you tell me if there is an error in my code

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Yes, I think it's safe to say there is an error in your code

  • #3
    New Coder
    Join Date
    Feb 2008
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post
    Maybe I should clarify...can you tell me what the error means or how I can fix it?

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Search this forum for "valid mysql resource", you will find this question has been asked and answered a hundred times before.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •