Professional Web Applications Themes

how to display variables within using echo command within html code - PHP Development

this is part of my code question? why the variable $name and $address does not display on the html page instead of real values I do get variable names if ($modify == 'print') { echo ' <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top">Name:</td> <td><font size="1"> <strong> <input name="name2" type="text" value="$name" size="100"> <br> <font size="2">note: name field cannot be changed</font></strong></font></td> </tr> <tr> <td>Address:</td> <td><input name="address2" type="text" id="address" value="$address" size="100"></td> </tr> </table> '; }; //Close connection with MySQL MySQL_close() ?> </td> </tr> </table>...

  1. #1

    Default how to display variables within using echo command within html code

    this is part of my code

    question?

    why the variable $name and $address does not display on the html page
    instead of real values I do get variable names
    if ($modify == 'print') {
    echo '


    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td valign="top">Name:</td>
    <td><font size="1"> <strong>
    <input name="name2" type="text" value="$name" size="100">
    <br>
    <font size="2">note: name field cannot be
    changed</font></strong></font></td>
    </tr>
    <tr>
    <td>Address:</td>
    <td><input name="address2" type="text" id="address" value="$address"
    size="100"></td>
    </tr>
    </table>


    ';
    };
    //Close connection with MySQL
    MySQL_close()
    ?>
    </td>
    </tr>
    </table>


    Bartosz Wegrzyn Guest

  2. #2

    Default Re: how to display variables within using echo command within htmlcode

    Hi,

    Bartosz Wegrzyn wrote:
    > this is part of my code
    >
    > question?
    >
    > why the variable $name and $address does not display on the html page
    > instead of real values I do get variable names
    > <td><input name="address2" type="text" id="address" value="<?php echo $address ?>"
    you may also write, with the same result:
    value="<?php echo '$address' ?>"
    or
    value="<?php echo "$address" ?>"

    remember html cannot display php values if you do not explicit the
    markup <?php ?> for php processor.

    php is a server side scripting language, html is interpreted client side
    by browsers...

    Ciao Gianfranzo

    --
    --
    ICQ#: 21258924
    Nick Gianfranzo
    Home page [url]http://www.gianfranzo.it[/url]
    Gianfranzo contro la guerra
    --

    Gianmarco Vanni Guest

  3. #3

    Default Re: how to display variables within using echo command within html code

    I found out that I could use require() or include() functions
    What do u think
    "Gianmarco Vanni" <gianmarcovannitin.it> wrote in message
    news:3F1D1804.3000904tin.it...
    > Hi,
    >
    > Bartosz Wegrzyn wrote:
    > > this is part of my code
    > >
    > > question?
    > >
    > > why the variable $name and $address does not display on the html page
    > > instead of real values I do get variable names
    >
    >
    > > <td><input name="address2" type="text" id="address" value="<?php
    echo $address ?>"
    >
    > you may also write, with the same result:
    > value="<?php echo '$address' ?>"
    > or
    > value="<?php echo "$address" ?>"
    >
    > remember html cannot display php values if you do not explicit the
    > markup <?php ?> for php processor.
    >
    > php is a server side scripting language, html is interpreted client side
    > by browsers...
    >
    > Ciao Gianfranzo
    >
    > --
    > --
    > ICQ#: 21258924
    > Nick Gianfranzo
    > Home page [url]http://www.gianfranzo.it[/url]
    > Gianfranzo contro la guerra
    > --
    >

    Bartosz Wegrzyn Guest

  4. Moderated Post

    Default Re: how to display variables within using echo command within html code

    Removed by Administrator
    Bartosz Wegrzyn Guest
    Moderated Post

  5. #5

    Default Re: how to display variables within using echo command within html code

    "Bartosz Wegrzyn" <blwegrzynlexon.ws> wrote in message
    news:UjcTa.24161$BM.7573218newssrv26.news.prodigy .com...
    > this is my new code
    > the problem is that varialebles are not past to print.php
    >
    > what am I doing wrong ???
    >
    <Deleted Lines>
    > //Assign contents of form to variables
    > //Customer Data
    > $name = $_POST['name'];
    <Deleted Lines>
    > if ($modify == 'print') {
    > echo ("name is $name<BR>");
    <Deleted Lines>

    Hi,

    We are taking it on trust that the html form has a field called 'name' and
    that it is assigned a value by the user to be posted to the PHP script,
    That being so it should display - Remember that PHP is case sensitive for
    variable names

    so having name = 'Fred' in html and
    $Fred =$_POS['fred'] in PHP isn't going to work. Fred !== fred

    I noticed earlier in the thread you were struggling with variables within
    strings

    echo " Name = '$fred' <br />"; will display Name = 'value of fred'
    whereas

    echo ' Name = "$fred" <br />'; will display Name = "$fred"

    The outer most quotes have to be double quotes for it to work.

    Returning to your posted variable problem, just add a debug line to print
    $name as soon as you have it - to make sure it really has arrived.
    The other way you can lose variables is inside functions, your code refers
    to what appears to be inline code as a function. if it really is code taken
    from a function ( i.e. not inline as shown ) the variable scope of the
    function will not include variables declared outside of the function unless
    declared as global. in other words there will be two variables called $name,
    one existing inside the function (un initialised) and one outside the
    function loaded with the posted data and otherwise unused.

    Cheers

    Ron


    Ron Guest

Similar Threads

  1. Replies: 2
    Last Post: October 13th, 10:31 AM
  2. echo multiple variables to flash
    By Raj_Sol in forum Macromedia Flash Data Integration
    Replies: 1
    Last Post: April 8th, 12:22 AM
  3. Replies: 3
    Last Post: October 24th, 10:51 AM
  4. Echo command option for db2
    By Blair Adamache in forum IBM DB2
    Replies: 1
    Last Post: August 1st, 07:14 PM
  5. [PHP] Display HTML/PHP code on a web page
    By Chris Shiflett in forum PHP Development
    Replies: 5
    Last Post: July 17th, 12:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139