View Full Version : merged threads- installing a script
MLLanser
04-28-2008, 06:14 AM
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
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 :confused:).
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
boogyman
04-28-2008, 05:38 PM
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
MLLanser
04-28-2008, 07:03 PM
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!!
MLLanser
04-28-2008, 07:14 PM
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...
boogyman
04-28-2008, 07:16 PM
edit your post to not include the Actual User / Pw Info...
That Is A Major Security Flaw
MLLanser
04-28-2008, 07:23 PM
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?
boogyman
04-28-2008, 07:33 PM
when posting computer code, please be sure to use
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
[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
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"];
$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.
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
end edit
MLLanser
04-28-2008, 07:46 PM
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?
boogyman
04-28-2008, 07:53 PM
try this.. create a new page with JUST the info below
<?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
MLLanser
04-28-2008, 08:02 PM
It says cant select database.... maybe I should delete the database and start over on that? This is getting frustrating....I copied and pasted right from the MySQL databases part so I know the db name is correct.... is there something else I should be putting in front of it? Like a path of sorts?
MLLanser
04-28-2008, 08:08 PM
I got it!!!! When I went in and created a new database, I used the database wizard which I didnt use the first time. This time it had me add my username right away..... so now it works....
Thank you so very much for all your help!!
MLLanser
04-29-2008, 02:43 AM
Hi there,
I was so happy to have it working earlier, but then I started getting this message..."Warning: session_start() [function.session-start]: open(/tmp/sess_c1ce974ba484c11adc55dd6dd7773d4c, O_RDWR) failed: Permission denied (13) in /home/mllanser/public_html/admin.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/mllanser/public_html/admin.php:2) in /home/mllanser/public_html/admin.php on line 2"
It happens on every page I have, just putting in the type of page I am on (e.g. If I am on the upgrade page, it says at /home/mllanser/public_html/upgrade.php:2)
What caused this?
I went through and started from scratch even to try to get rid of it, and it didnt do a thing.
Help!
Thanks!
MLLanser
04-29-2008, 11:51 AM
Ok I figured it all out. Thanks for the help anyway.
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
I thought that's what the error said-- no database selected. I guess that could also mean the DB doesn't exist, though.
boogyman
04-29-2008, 07:51 PM
@Jas - I meant good advice
I understood your comment, boogyman. :) I was just saying that I figured that perhaps the DB select was missing entirely-- although it's unlikely if the script was purchased. Anyway, the problem is solved. :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.