hi all im getting the following error
PHP Notice: Array to string conversion in /home/public_html/includes/database.php(23) : eval()'d code on line 1
in this file

<?php
$link = @mysqli_connect($hostname, $username, $password, $database);
if (!$link) {
    die('Could not connect !');
    exit();
}
else{
    mysqli_set_charset($link,'utf8');

    }
$sqlcf = 'select Variable, Value from '.$table_prefix.'site_settings where IsRead = 0';
$qrycf = mysqli_query($link,$sqlcf);
if(!$qrycf)
    die('Can not load config data !');
elseif(mysqli_num_rows($qrycf)>0){
    while($rowcf = mysqli_fetch_assoc($qrycf)){
        if('filetype'==trim(strtolower($rowcf['Variable'])))
            $$rowcf['Variable'] = explode(',', $rowcf['Value']);
        elseif('numof_record_perpage'==trim(strtolower($rowcf['Variable'])))
            $$rowcf['Variable'] = intval($rowcf['Value']);
        elseif('default_language'==trim(strtolower($rowcf['Variable'])))
            $_SESSION['lang'] = isset($_SESSION['lang'])?$_SESSION['lang']:$rowcf['Value'];
        else eval("$\$rowcf['Variable'] = \"$rowcf[Value]\";");
        }
    }
else die('Can not find setting table !');

and im not sure what i have to do can someone please advice many thanks in advance jan x

So.. first, did you write this?

Are you aware of what "$$" variables do?

(
for those who don't, they make a (scoped?) variable with the "VALUE" as the variable NAME; eg.

$a = "hello";
$$a = "world";

You now have $a = "hello" and $hello = "world"; 
)

I assume, then, that since you are attempting to eval code that is reading the value of the code as a string but is really an array "index" of a hash table that you are making some sort of odd behavior that cannot be resolved.

Which begs the next question - why are you using eval?

You are not being handed a stringified chunk of code that you need to arbitrarily execute on your server (and if you are, that's pretty dangerous). Your else can simply be served with (what I think is) identical behavior as:

else $$rowcf['Variable'] = $rowcf['Value'];

Of course.. YMMV.. I don't often write code that has a side effect of making variables for me. Generally, I find this to be confusing and often damaging behavior in a program. Such as, what if the $rowcf["Variable"] value turns out to be "$_SESSION" and you have now blown away a super global (of course, depending on scope here...)?

From a personal perspective, I would avoid doing what you are doing here and find another solution. However, I don't know your experience level, or if you know exactly why you are doing this. If you do, and you are comfortable with it, carry on :)

Alternatively, if you insist on the eval, I believe you have a typo:
else eval("$\$rowcf['Variable'] = \"$rowcf[Value]\";");
shoud probably be
else eval("$\$rowcf['Variable'] = \"$rowcf['Value']\";"); //notice single quotes around 'Value'
however, I do not know if that is the actual cause of your problem.

I hope that helps,

Ryan

i didnt write the script it came in some software that was purchased and tyring to get it working my levels are very basic and have googled most or problems but was struggling with this jan x

ive tried putting the

else eval("$\$rowcf['Variable'] = \"$rowcf['Value']\";");

but then im getting a red cross on that line

Hello J,

My thought was there is something broken in the line Ryan pointed out as well so if this was mine I would be printing (echo?) those variables one by one to see if they look OK before the else eval line is hit.

Hey guys...

I have a lot so far from watching mmtuts on youtube but there is a lesson on php login and i am just wondering if he is doing his if statements correctly? Here is the video link..

https://youtu.be/xb8aad4MRx8

I thought that it should be an if () {} elseif (){}

But my main question is on using implode... i got this to work momentarily and suddenly, it is not inserting into my 2nd database..... i have checked my queries and there are no errors..

@gdi888, start your own thread. You will need to post example code to see what you are doing to see if we can help.

By posting in your own thread, you will get much higher quality answeres specific to your problem, and you will make a lot of people less upset - it's a bit rude to hijack another thread for something pretty unrelated to it.

@janicemurby

try this:

else eval("$$rowcf['Variable'] = $rowcf['Value'];");
or
else eval("$\$rowcf['Variable'] = $rowcf['Value'];");

Im not sure what the escape for the 2nd $ will do... it seems odd to need it.. but again, I don't eval in php often, so I'm generalizing based on how other script languages work...

if you are really dead set on using column names to create variables, then you should just manually do that. I don't understand the need for what you are doing. If this is a lazy way to iterate over all results, then... I mean... there are far more efficient ways of being lazy :-/

Can you explain why there is a need to do that eval (or getting variables named as the column names)?

im just going by what is in the script that came in the purchase but i do welcome other ways of doing things its just how the heck do i do it hun :)

did the two suggestions above not work?

This is why you should never use third party software that you don't understand or that hasn't been tried and tested to death. This code IMO should never be used in the wild. You simply have a vehicle for storing settings values into an array, the is no reason I can see for $$. You know the element names of interest and simply add all the others to the array anyway. Seems like overkill / poor design.

In addition. If this is procedural code and it appears to be, then variables you create in the loop could overwrite variables of the same name that already exist - not just the superglobals mentioned by Ryan - or they may get overwritten by variables of the same name created downstream of this piece of code.