Undefined variable error in array


Joined
Apr 17, 2021
Messages
5
Reaction score
0
I have a collection of check boxes all with the name c[] but different values. From php8 the code below works but gives me an 'Undefined variable $sql_c’ warning (perhaps this error was just suppressed in earlier versions?). I was given the code years back and have now updated it with numerous 'if isset()' functions, but if I do that to the $sql_c function, I get no results. Any help would be appreciated.

PHP:
if (isset($_POST['submit']) && isset($_POST['c'])) {
    
$sql="stuno,fname,lname";

if(isset($_POST['c']) && $_POST['c']=="") {$c = array(); }

foreach ($_POST['c'] as $cID) {

$sql_c .= ",".$cID;  // "Undefined variable $sql_c" warning

if (isset($numCat)) {$numCat = $numCat + 1;}

}

$sql = $sql . $sql_c;         

$sql="SELECT"." ".$sql." "."FROM records ORDER BY fname";

[email protected]_query($dbcnx, $sql);
 
Ad

Advertisements

Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top