0

I am very new to PHP and I was wondering if I could get some feedback on the code below, I don't see why its not working.

$i = 0;
$companyService = $_POST['companyService']; // Array variable


for ($i; $i<count($companyService); $i++) {

    $service = $companyService[$i];
    echo $service; // works and provides correct value
    echo $companyId; // works and provides correct value
    $queryService = "INSERT INTO `companySpTable` (`companyId`,`serviceId`) VALUES ('".mysqli_real_escape_string($link,$companyId)."' ,'".mysqli_real_escape_string($link,$service)."'";

    if(!mysqli_query($link,$queryService)) {

         $error = "<p> Query not executed</p>".$error;


    }
u_mulder
  • 54,101
  • 5
  • 48
  • 64
Moe K
  • 1
  • (1) `not working` is entirely too vague for anyone to know what is going on. (2) You should use parameters, not munge query strings with such input. – Gordon Linoff May 27 '18 at 12:48
  • (3) Add a `)` in your query. – u_mulder May 27 '18 at 12:48
  • `$error` is never defined so that won't help. Use the error function, http://php.net/manual/en/mysqli.error.php. Also the `for` can define the `$i`, and I'd use a `foreach`. – user3783243 May 27 '18 at 12:48

0 Answers0