Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: merged threads- installing a script

  1. #1
    Join Date
    Apr 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool merged threads- installing a script

    Hi there,
    I purchased a script today and tried my best to install it. I got past most of it, but there is a part I cannot get past. The error message I am getting is "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mllanser/public_html/config.php on line 29
    No database selected"
    And here is the coding right before and after that line....


    $queryxx = "DELETE FROM ad_clicks WHERE day!='$da'";
    mysql_query($queryxx);

    $q2 = mysql_query("SELECT * FROM settings");
    while($r2=mysql_fetch_array($q2))
    {
    $set[$r2[setname]]=$r2["setvalue"];
    }
    mysql_query("UPDATE settings SET setvalue='0', set_day='{$da}' WHERE set_day!='{$da}' AND set_day>'0'") or die(mysql_error());
    $user=$_COOKIE['usNick'];


    The error seems to be coming from the line that starts with "while"
    Is there anything you can do to help??
    Thanks so much!
    Michelle

  2. #2
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    The error messages seems to be saying that you did not select a database to query from, thus making the fetch_array statement invalid because the query did not go through (but I would have thought that you would have gotten an error on the query, not the fetch_array ).

    1) make sure the database exists
    2) make sure that the table(s) exist(s)
    3) make sure there is a MySQL_Select_DB() function before all of the queries
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by Jas View Post
    1) make sure the database exists
    2) make sure that the table(s) exist(s)
    3) make sure there is a MySQL_Select_DB() function before all of the queries
    1. good
    2. good
    3. not necessary unless you are switching between databases.

    It is important to use that method when you initially connect, however after you initially connect the connection remembers the database, unless you are using [icode]mysqli[/code], which you need to apply the connection link anyway

  4. #4
    Join Date
    Apr 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok, here is all the coding, and when I started this project I did struggle to come up with the db username (it wasnt working) and I know I have the db name exactly how it is listed.... but anyway here is all the code and you can let me know what I should do from here... if there is any way to take it out or alter it, or anything....

    <?php

    $dhost = "localhost"; //usually localhost, or ip
    $dusername = "xxxx"; // database user
    $dpassword = "xxxxxx"; // database pass
    $ddatabase = "xxxxxxx"; // database name

    $con = mysql_connect($dhost, $dusername, $dpassword) or die("Cannot Connect");
    mysql_select_db($ddatabase, $con);

    if($_COOKIE["usNick"] and $_COOKIE["usPass"])
    {
    $q = mysql_query("SELECT * FROM tb_users WHERE username='{$_COOKIE['usNick']}' AND password='{$_COOKIE['usPass']}'") or die(mysql_error());
    if(mysql_num_rows($q) == 0)
    {
    $_COOKIE['usNick'] = false;
    $_COOKIE['usPass'] = false;
    } else {
    $loggedin = 1;
    $r = mysql_fetch_array($q);
    }
    }
    $da = date("j");

    $queryxx = "DELETE FROM ad_clicks WHERE day!='$da'";
    mysql_query($queryxx);

    $q2 = mysql_query("SELECT * FROM settings");
    while($r2=mysql_fetch_array($q2))
    {
    $set[$r2[setname]]=$r2["setvalue"];
    }
    mysql_query("UPDATE settings SET setvalue='0', set_day='{$da}' WHERE set_day!='{$da}' AND set_day>'0'") or die(mysql_error());
    $user=$_COOKIE['usNick'];
    ?>

    And this is going to http://www.DivinitysClicks.info if you want to check it out. It seems to go farther if I dont even have the config file there, at least then it will get somewhere!!
    Last edited by MLLanser; 04-28-2008 at 07:22 PM.

  5. #5
    Join Date
    Apr 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Also, what table should I be looking for? There are 9 tables there, but since I know nothing about php coding, I have been doing my best up to this point...

  6. #6
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    edit your post to not include the Actual User / Pw Info...
    That Is A Major Security Flaw

  7. #7
    Join Date
    Apr 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I was just trying to show you how it was so you could see that I did that part right, especially after struggling with it last night.... I am getting hung up on the localhost thing, should it just be localhost or should I replace it with an ip address or something else?

  8. #8
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    when posting computer code, please be sure to use [code][/code] tags. its formatted in a way that makes it easier for us to help you.

    now back to your code...

    mysql_select_db($ddatabase, $con);
    you do not need the $con as a second parameter
    Code:
    [quote]mysql_select_db($ddatabase);
    I would suggest using white-space to allow for debugging and viewing purposes. its generally easier to debug code if the structure is indented properly.

    replace
    if($_COOKIE["usNick"] and $_COOKIE["usPass"])
    with
    Code:
    if($_COOKIE["usNick"] && $_COOKIE["usPass"])
    the only other "error" I can see is on line 34, you need to add quotations marks
    $set[$r2[setname]]=$r2["setvalue"];
    Code:
    $set[$r2['setname']]=$r2["setvalue"];
    from the code you posted this is what I believe you are attempting to do

    1) connect
    2) set the username/password from cookie values
    3) delete ads that were not intended for today
    4) declare an array of settings from the settings
    5) update the settings table
    6) assign the username to a variable

    if that is not what you are trying to do... then please elaborate or expand on your current code

    I would suggest against using the $_COOKIE super global, but rather a $_SESSION, which doesn't allow the user to modify his/her settings manually.

    Edit: begin edit


    I was just trying to show you how it was so you could see that I did that part right, especially after struggling with it last night.... I am getting hung up on the localhost thing, should it just be localhost or should I replace it with an ip address or something else?
    if the mysql database is on the same computer as the file server (apache) then localhost should work. if the database is loaded on a separate computer, than you would need to assign the ip of the other server as the host... typically the mysql database is loaded on the same computer, and it would be clearly stated from your ISP if it on a different server (computer)

    If you are having trouble, be sure your host (ISP) allows for mysql databases, and that the mysql server is running. you may try to put the IP as the $dhost, or you could also try putting the website address, as that will find the IP of the machine where the file server is located

    Edit: end edit
    Last edited by boogyman; 04-28-2008 at 07:38 PM.

  9. #9
    Join Date
    Apr 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It is still giving me the error message "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mllanser/public_html/config.php on line 29
    No database selected"
    So how can I make sure that I have my database in there correctly? I put it exactly how it is in the MySQL admin area....maybe I should start over with the database?

  10. #10
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    try this.. create a new page with JUST the info below

    Code:
    <?php
    
    $dhost = "localhost"; //usually localhost, or ip
    $dusername = "xxxx"; // database user
    $dpassword = "xxxxxx"; // database pass
    $ddatabase = "xxxxxxx"; // database name
    
    $con = mysql_connect($dhost, $dusername, $dpassword) or die("Cannot Connect");
    
    if(!mysql_select_db($ddatabase))
        die("cant select database");
    else
        echo "--Connected";
    
    ?>
    if that prints "cant select database" then your database name is incorrect
    if that prints "Cannot Connect" then either the host/username/password is incorrect
    if that prints "--Connected" then you are connected and there is something wrong with your queries

Bookmarks

Posting Permissions

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