Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

just moved php/mysql application to new server, getting Warning invalid argument supplied Why?

during migration to new server i ran into the followling errors on one of my sites

See attached pic for error message

the foreach is attached

foreach (getSelectQuestions() as $key=>$value):?>
			<option value="<?=$key?>" <?=$selected[$key]?>><?=$value?>
			<?endforeach;?>
			</select>
==============================================
function getSelectQuestions()
{
    global $db;
 
    $sql  = "SELECT Q_ID, Q_TEXT FROM QUESTION WHERE Q_ID IN (SELECT DISTINCT Q_ID FROM OPTION_FIELDS) ORDER BY Q_TEXT";
 
    $result = mysql_query($sql,$db);
 
    while ( $row = mysql_fetch_assoc($result) )
    {
        $O[$row['Q_ID']]=$row['Q_TEXT'];
    }
 
    return $O;
 
}

Open in new window

warningError.JPG
0
justmelat
Asked:
justmelat
  • 4
  • 3
1 Solution
 
staarlandCommented:
Are you sure that you have turned on short tags use in php.ini ?
0
 
justmelatAuthor Commented:
didn't realize the image would show correctly:  here is the warning that appears in my dropdown

Warning:invalid argument for foreach() in /usr/local/www/urls/dandy.com/include/templates/options.php on line 75
0
 
Ionut A. TudorPHP ProgrammerCommented:
That error is beause the function doesn't returns an array, change the function into the below code, and it shuld get you rid of those warnings. Good luck

function getSelectQuestions()
{
    global $db;
    $O = array();
 
    $sql  = "SELECT Q_ID, Q_TEXT FROM QUESTION WHERE Q_ID IN (SELECT DISTINCT Q_ID FROM OPTION_FIELDS) ORDER BY Q_TEXT";
 
    $result = mysql_query($sql,$db);
 
    while ( $row = mysql_fetch_assoc($result) )
    {
        $O[$row['Q_ID']]=$row['Q_TEXT'];
    }
 
    return $O;
 
}

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
justmelatAuthor Commented:
short_open_tags = On
0
 
justmelatAuthor Commented:
wow al3cs12: that got it

I have a feeling i am going to be plagued with these type of errors when this goes live monday.

thanks so much for your help.
0
 
Ionut A. TudorPHP ProgrammerCommented:
Change your function with my above code, it should resolve your problem and not returning any warnings. Good luck
0
 
Ionut A. TudorPHP ProgrammerCommented:
No problem, glad to help, the error was caused because the sql query didn't cacth and rows from mysql database, so it didn't created the array. The solution was to create an array at the start of the function so that when using foreach it will not return any warning as foreach statment takes only an array as its argument.
0
 
justmelatAuthor Commented:
Thank you so much, that explanation is an even bigger help.

Thanks again.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now