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";

$result=@mysqli_query($dbcnx, $sql);
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top