Jump to content

help on weird variable substition


jacaranda

Recommended Posts

Hi, hope someone could shed a light on this...

 

Im having trouble displaying the correct value of a variable.. which is take from a database...

 

I have this for the query part...

 

  $query = "SELECT * FROM auth_users WHERE user_id LIKE '{$_SESSION[userId]}' ORDER BY work_week DESC";

  $result = mysql_query($query) or die('Query failed. ' .mysql_error());

  $row = mysql_fetch_array($result);

 

when I do an echo, say:

 

echo "<p>$row[activity_1]";

 

output is correct... say 'this is the content' .. (w/o quotes)

 

But when i put the $row[activity_1] inside a textbox 'value=' part.. the only thing that's displayed is 'this'... after the space, nothing..

 

<td width="70%">

<input disabled="yes" type="text" name="LWActivity1" size="20"     

                                                <?php echo "value= $row[activity_1]" ?>>

<td>

 

Itried playing around with the quotes and things, but nothign...

I hope this is enough info, Thanks for your help...

Link to comment
https://forums.phpfreaks.com/topic/46635-help-on-weird-variable-substition/
Share on other sites

 

tried this once, but the value didn't change.. still the one word output...

 

 

Should be this

<input disabled="yes" type="text" name="LWActivity1" size="20" value="<?php echo $row['activity_1']; ?>">

Ray

Ya we natuarally do this. but he wanna echo 'value' also with php echo

 

it caused a '`T_STRING' or `T_VARIABLE' or `T_NUM_STRING' ' parse error.. also tried this..

echo "<p>$row[activity_1]";

displays the contect perfectly, but not in the html form...

 

 

 

$row[activity_1] is not right use $row['activity_1'].

and use this

<input disabled="yes" type="text" name="LWActivity1" size="20"      

                                                <?php echo " value= $row['activity_1']" ?>>

My code should work.

 

The other way of writing it would be:

<?php
echo '<input disabled="yes" type="text" name="LWActivity1" size="20" value="' . $row['activity_1'] . '">';
?>

 

or

<?php
echo '<input disabled="yes" type="text" name="LWActivity1" size="20" value="{$row['activity_1']}">';
?>

 

Ken

 

(edit: was posting this as you posted your reply)

Well, it did work sir.

Thanks very much!

 

 

My code should work.

 

The other way of writing it would be:

<?php
echo '<input disabled="yes" type="text" name="LWActivity1" size="20" value="' . $row['activity_1'] . '">';
?>

 

or

<?php
echo '<input disabled="yes" type="text" name="LWActivity1" size="20" value="{$row['activity_1']}">';
?>

 

Ken

 

(edit: was posting this as you posted your reply)

yeah, ken made it perfectly sure that i notice the space in between..

thanks too..

 

 

well if activity_1 has spaces in it you will get an error

<input disabled="yes" type="text" name="LWActivity1" size="20" <?php echo "value='".$row['activity_1']."'" ?>>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.