0

I'd like to do something like this :

 <select name="cities">
 <option value="<?php=$row['city']?>"><?php=$row['city']?></option>
 </select>

But the previous code doesn't work.

Does somebody know how to fix this ?

5 Answers 5

5

I think you mean either <?= $variable ?> or <?php echo $variable; ?>. You can't combine the two.

Sign up to request clarification or add additional context in comments.

Comments

4
<option value="<?php echo $row['city']; ?>">
  <?php echo $row['city']; ?>
</option>

You have to echo it out ;)

Comments

3

I think it's the <?php=.

Either try <?php echo $row['city'] ?> or <?= $row['city'] ?>.

The second version is the shorthand which is not always enabled and therefore there's no guarantee that it's going to work.

Comments

2

This is not possible:

<?php=$row['city']?>

I guess you mean:

<?php echo $row['city']; ?>

See: Escaping from HTMLDocs

If you want to use this:

<?= $row['city'] ?>

Get PHP 5.4 or enable short_open_tagIni in your php.ini.

Comments

1

there is no such thing as <?php= [...] ?>
use <?php echo [...] ?> or <?= [...] ?> instead. I personally prefer the first.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.