Deviant Logo

Can someone help me with this PHP Code (add variable into input form value)?

post details top
Jun 3rd, 2010
post details top


What I’m trying to do is load a variable from a cookie, and make that variable the value for the input checkbox. Code is below:

$username = $_COOKIE['ID_my_site'];

echo 'Add me as:
‘;
echo ‘

1 Comment

  • Christopher R

    The problem with your code is that have a second set of < ?php tags when you don't need them.

    Your code should be as follows:

    $username = $_COOKIE['ID_my_site'];

    echo 'Add me as:
    ‘;
    echo ‘

    ‘;
    echo ‘
    value="' . $username . '" /> Camera
    ‘;
    echo ‘
    Commentator
    ‘;
    echo ‘

    ‘;
    echo ‘
    ‘;
    echo ‘
    ‘;
    echo ‘‘;
    ?>

    Just be aware that I changed
    < ?php echo $username; ?>

    to:
    ‘ . $username . ‘

    Since you are echoing out the html using single quotes, which is the better way to do it, you need to specify the variable of $username outside of the string, and use concatenation ( the period ) to join everything together so you can echo each line correctly.

Leave a Reply