iEoj
iEoj

Reputation: 70

Dropbox returning no results. php

Ive used this code in other projects I've made, for some reason now it is not working. To me it should work but I'm hoping someone will see the mistake I'm missing

//Actual Function
function get_data(){
   $mealData = mysql_query("SELECT `MealID`, `MealOption` FROM `menu` ");
   while($record = mysql_fetch_array($mealData)){
       echo '<option value="'. $row['`MealOption`'] . '">'.$row['`MealOption`'].'</option>';
   }

//   HTML
<select name="Meal">
<?php  get_data() ?>
</select><br>

// Including
<?php
    include_once '@add_customer.php';
?>

Upvotes: 0

Views: 25

Answers (2)

Tamil Selvan C
Tamil Selvan C

Reputation: 20229

Don't use backtick ` in array key name

Change

echo '<option value="'. $row['`MealOption`'] . '">'.$row['`MealOption`'].'</option>';

to

echo '<option value="'. $row['MealOption'] . '">'.$row['MealOption'].'</option>';

and just use include_once 'add_customer.php'; not include_once '@add_customer.php';

Upvotes: 0

Pedro Lobito
Pedro Lobito

Reputation: 98981

Try this instead:

function get_data(){
   $mealData = mysql_query("SELECT `MealID`, `MealOption` FROM `menu` ");
   while($record = mysql_fetch_array($mealData)){
         $mealOption = $row['MealOption'];
          echo "<option value='$mealOption'>$mealOption</option>";
      }
<select name="Meal">
<?php  get_data() ?>
</select><br>


 // Including
<?php
include_once 'add_customer.php';
?>

Your backticks were misplaced.
I always prefer to assign the MySQL output of to a variable first and then simply use it inside double quotes, it's easier to read.


If you're not sure where the error is, add the following code at the top of your php script, this way you'll be able to detect any errors your script may have, remove it when in production mode.

error_reporting(E_ALL);
ini_set('display_errors', '1');

Upvotes: 1

Related Questions