Mithun Ds
Mithun Ds

Reputation: 131

How to assign the variable value to radio button's value in php

Hi i am trying to assign the php variable value to the radio button's value

Here is what i am doing. But i am not able to see any value when i am alerting the value through java-script.

code:

  echo "<td class='ad'>" . $row['address'] . "</td>";
  echo "<td>"; 
  echo '<input type="radio" name="address" value='$row['address']'/>';

i want to assign the $row['address'] value to input value=

how can i do this?

Upvotes: 1

Views: 1480

Answers (3)

user2355660
user2355660

Reputation:

If you're not using the in-php echo (you're out of php code), you can write this:

< input name="address" type="radio" value="< ?= $row['address']; ? > Hope to be useful. I added some spaces to make my answer ok

Upvotes: 1

DevZer0
DevZer0

Reputation: 13525

you will need to use . which is the string concatenation operator in php. what you have done is almost correct but you have not concatenated the string value with the php variable properly.

echo '<input type="radio" name="address" value=' . $row['address'] . '/>';

Upvotes: 0

gherkins
gherkins

Reputation: 14973

You got it right in the 1st line, while the 3rd should be like this:

echo '<input type="radio" name="address" value="' . $row['address'] . '"/>';

see http://php.net/manual/en/language.operators.string.php

Upvotes: 1

Related Questions