0

What would be the syntax for "$dish[$i][$j]=$_post[$ds];" ? it's returning error "Undefined variable: _post in C:\wamp64\www\pizzeria\checkout.php on line 18"

<?php

$ftable="SELECT * FROM dish Group By DishType";
            $ftableq=mysqli_query($con,$ftable); 
            if(isset($ftableq)){
            while($frows=mysqli_fetch_assoc($ftableq))
            {$i=1;
              $dt=$frows['DishType'];
              $dtable="SELECT * FROM dish where DishType='$dt'";
            $dtableq=mysqli_query($con,$dtable); 
            if(isset($dtableq)){
            while($drows=mysqli_fetch_assoc($dtableq))
            {$j=1;
                $ds=$drows['DishName'];
                echo $ds;
                $dish[$i][$j]=$_post[$ds];
               
                ?>
                <html>
                <head></head>
                <body>
                    
                    <label><?php echo $dish[$i][$j];?></label>
                    
                    </form>
                </body>
                </html>
                <?php 
                $j=$j+1;
            }}
            $i=$i+1;
        }}
?>
  • It would normally be `$_POST` – Nigel Ren Jul 19 '20 at 08:04
  • without any brackets? Right? –  Jul 19 '20 at 08:05
  • As it's an array it would be `$_POST[$ds]` – Nigel Ren Jul 19 '20 at 08:06
  • If you `print_r($_POST);` you should see that it contains. – Nigel Ren Jul 19 '20 at 08:06
  • Yes, that is the concept I'm using. But the problem is, it is showing syntax error. –  Jul 19 '20 at 08:09
  • It would help if you show the error and indicate which line it's indicating. – Nigel Ren Jul 19 '20 at 08:10
  • I've updated the question. I'm having problem with line 18. "$dish[$i][$j]=$_post[$ds];" and the error is "Undefined variable: _post in C:\wamp64\www\pizzeria\checkout.php on line 18" which means I'm missing some syntax. –  Jul 19 '20 at 08:17
  • As it should be capitals (as I showed in my first comment). – Nigel Ren Jul 19 '20 at 08:24
  • Not working. I've already tried that. –  Jul 19 '20 at 08:26
  • Whatever it is you are trying to do here you are generating invalid HTML. It appears that you are generating the entire HTML content in a loop - so potentially there would be many entire HTML pages being generated in this single script. Also, assuming that you are using `$_POST` variables then your code is vulnerable to SQL injection. The multiple `nested queries` are not needed - this could be done in a single query – Professor Abronsius Jul 19 '20 at 08:35
  • $_POST["$ds"] is working. Thank you. –  Jul 19 '20 at 08:35
  • @ Professor Abronsius Sir I know that it could be done but this is not complete code it's just for understanding purposes, I'm using different functions with every data that's why I'm using it in this way and the HTML portion is for your understanding this is not the actual code. –  Jul 19 '20 at 08:40
  • The main problem I was facing that the texts in the variables had spaces in them. There should not be any space in the parameter of a Post variable. So, I trimmed and replaced the spaces with function 'str_replace();' all the issues were solved. Thanks again. –  Jul 19 '20 at 09:07

0 Answers0