0

i was trying to echo my data using html but unfortunately it's getting an error:

enter image description here

this is my code :

<?php echo form_open("dashboard/edit_product/$product_id");?> <div class="form-group"> <div class="col-sm-10"> <input class="form-control" type="text" name="r_name" value="<?php echo($r_name); ?>"> </div> </div> <?php echo form_close(); ?> 
11
  • Why space between <? and php at <? php echo($r_name); ?> and what is the value of $r_name?? Commented Jan 22, 2016 at 5:20
  • im sorry it doesn't have a space. i just had a typo error. the value of r_name is a recipe that is stored in my database Commented Jan 22, 2016 at 5:23
  • print_r($r_name) and paste its value Commented Jan 22, 2016 at 5:25
  • Can you try without the brackets in echo? Like <?php echo $r_name; ?> or if its an array like <?php echo $r_name[0]; ?> Commented Jan 22, 2016 at 5:29
  • the code above is my line 68 sir Commented Jan 22, 2016 at 5:32

2 Answers 2

1

From debugging your framework from your comments the answer is that $r_name is an array, not a string, as the error suggests. The codeignitor function form_input takes parameter one as an array. So you probably want to pull the value from that array:

<input class="form-control" type="text" name="r_name" value="<?php echo $r_name['value']; ?>"> 

Depending on how that value is stored this might open you to XSS injections consider sanitizing that data as well. https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet

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

Comments

0

$r_name is an array. You should first print_r($r_name) to check keys and values for array. Once you know keys, you may further use them to get value. e.g echo $r_name[0]

6 Comments

Use above method and try, I'm sure you'll be able to fix this.
sir where will I put the print_r($r_name)?
Put it before form, or any where on page where you could see output. try it.
a minute sir. i'll try it
Array ( [name] => r_name [id] => r_name [type] => text [style] => width:300px; [value] => Mango Float ) that is the result sir. i just want the recipe Mango Float to be in my input
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.