how to display variables within using echo command within html code

This is a discussion on how to display variables within using echo command within html code within the alt.comp.lang.php forums, part of the PHP Programming Forums category; this is part of my code question? why the variable $name and $address does not display on the html page ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-22-2003
Bartosz Wegrzyn
 
Posts: n/a
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>


Reply With Quote
  #2 (permalink)  
Old 07-22-2003
Gianmarco Vanni
 
Posts: n/a
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 http://www.gianfranzo.it
Gianfranzo è contro la guerra
--

Reply With Quote
  #3 (permalink)  
Old 07-22-2003
Bartosz Wegrzyn
 
Posts: n/a
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" <gianmarcovanni@tin.it> wrote in message
news:3F1D1804.3000904@tin.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 http://www.gianfranzo.it
> Gianfranzo è contro la guerra
> --
>



Reply With Quote
  #4 (permalink)  
Old 07-22-2003
Bartosz Wegrzyn
 
Posts: n/a
Default Re: how to display variables within using echo command within html code

this is my new code
the problem is that varialebles are not past to print.php

what am I doing wrong ???

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><em><font size="1" face="Verdana, Arial, Helvetica,
sans-serif"><strong>LEXON
- Mysql Database</strong></font></em> </td>
</tr>
<tr>
<td align="left"><p><strong>Modify - Delete - Print (Customer &amp;
Workorder)<br>
<br>
</strong></p></td>
</tr>
<tr>
<td align="left">
<?php
$host = "localhost";
$login_name = "xxx";
$password = "xxx";
//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");

//Select the database we want to use
MySQL_select_db("lexon") or die("Could not select database");

//Assign contents of form to variables
//Customer Data
$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$phone = $_POST['phone'];
$ss = $_POST['ss'];
$cc = $_POST['cc'];
$exp = $_POST['exp'];
$notes = $_POST['notes'];
//Wordorder Data
$date = $_POST['date'];
$time = $_POST['time'];
$service = $_POST['service'];
$due = $_POST['due'];
$special = $_POST['special'];
$extrawork = $_POST['extrawork'];
$adddue= $_POST['adddue'];
$company= $_POST['company'];
$installer= $_POST['installer'];
$total = $due + $adddue;

$modify = $_POST['modify'] ;
//echo ("$modify");

//function to update customer and workorder
if ($modify == 'modify') {
$updatecustomer = "UPDATE addressindex SET address='$address', city='$city',
state='$state', zipcode='$zipcode', phone='$phone', ss='$ss', cc='$cc',
exp='$exp', notes='$notes' WHERE name='$name'";
$updateworkorder = "UPDATE workorder set date='$date', time='$time',
service='$service', due='$due', special='$special', extrawork='$extrawork',
adddue='$adddue', company='$company', installer='$installer', total='$total'
where name='$name'";
$result = mysql_query($updatecustomer);
$result2 = mysql_query($updateworkorder);

//Code to check if statement executed properly and display message
if ($result) {
echo("Customer data updated sucessfully<br>");
} else {
echo("An error has occured<br>");
}

if ($result2) {
echo("Work Order data updated sucessfully<br>");
} else {
echo("An error has occured<br>");
}
};

//function to delete customer and workorder

if ($modify == 'delete customer') {
$deletecustomer = "DELETE from addressindex WHERE name='$name'";
$result3 = mysql_query($deletecustomer);

//Code to check if statement executed properly and display message
if ($result3) {
echo("Customer data deleted sucessfully<br>");
} else {
echo("An error has occured<br>");
}

};

if ($modify == 'delete workorder') {
$deleteworkorder = "DELETE from workorder where name='$name'";
$result4 = mysql_query($deleteworkorder);

//Code to check if statement executed properly and display message
if ($result4) {
echo("Work Order data deleted sucessfully<br>");
} else {
echo("An error has occured<br>");
}
};

if ($modify == 'print') {
echo ("name is $name<BR>");
echo ("Preparing workorder - Please wait...");

echo '

<META HTTP-EQUIV="Refresh"
CONTENT="4;URL=http://lexon.ws/login/print.php">



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

"Bartosz Wegrzyn" <blwegrzyn@lexon.ws> wrote in message
news:B4cTa.24155$BM.7571069@newssrv26.news.prodigy .com...
> I found out that I could use require() or include() functions
> What do u think
> "Gianmarco Vanni" <gianmarcovanni@tin.it> wrote in message
> news:3F1D1804.3000904@tin.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 http://www.gianfranzo.it
> > Gianfranzo è contro la guerra
> > --
> >

>
>



Reply With Quote
  #5 (permalink)  
Old 07-23-2003
Ron
 
Posts: n/a
Default Re: how to display variables within using echo command within html code

"Bartosz Wegrzyn" <blwegrzyn@lexon.ws> wrote in message
news:UjcTa.24161$BM.7573218@newssrv26.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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:13 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0