-2

I have 2 Table first is a list of 1 million staff, I have successfully loaded a wildcard search to search through staff. I would like to use results from my wild card search and select the correct staff (using radio buttons or links, I tried with radio buttons)add a comment and this will populate the second table 'recommendations'.

    $str = $_POST["search"];
    echo $str;
    $sql = "SELECT `ID` AS ID,`NAME` AS NAME,GROUP_CONCAT(`ACCOUNT_NO` SEPARATOR ',') AS ACC,FROM cust WHERE `ID` LIKE '%$str%' GROUP BY `ID`";
    $result = $conn->query($sql);
    $cif1 = "";
                  echo "<table id='example1' class='table table-bordered table-striped'><th></th><th>NAME</th><th>ID</th><th>ACC</th>";
                  if($result->num_rows > 0) {
                      while($row = $result->fetch_assoc()){
                      echo "<tr><td><input type='radio' id='".$row['ID']."' name='cifq' <?"value='".$row['ID]."'>
                          <td>".$row['NAME']."</td><td>".$row['ACC']."</td><td>".$row['CIF']."</td></td>";
                  }echo "</table>";
                  }
                  else
                  {
                      echo "0 Results";
                  }
}

I am getting an error when for using the name cifq in $_POST["cifq"] when i try to use the values from the first query in the second.

Please help if you have a better way

johnyk105
  • 9
  • 2
  • 1
    **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman Mar 22 '22 at 09:29

1 Answers1

0

change

<tr><td><input type='radio' id='".$row['ID']."' name='cifq' <?"value='".$row['ID]."'>

to

<tr><td><input type='radio' id='".$row['ID']."' name='cifq' value='".$row['ID']."'>

There's a php <? php opening tag remove that. Also 'is missing in $row['ID].

And if you want the same name for multiple inputs use [], in your case it would be name='cifq[]'.

Shoyeb Sheikh
  • 2,659
  • 2
  • 10
  • 19