php-general Digest 4 Aug 2010 07:23:47 -0000 Issue 6878

Topics (messages 307297 through 307308):

Encoding for W3C Validation
        307297 by: Rick Dwyer
        307298 by: Sebastian Ewert
        307299 by: Ashley Sheridan
        307300 by: Shreyas Agasthya
        307301 by: Rick Dwyer
        307302 by: Ashley Sheridan
        307303 by: Rick Dwyer
        307304 by: Sebastian Ewert
        307305 by: Rick Dwyer
        307306 by: Ashley Sheridan
        307307 by: Rick Dwyer

Re: displaying and updating records in a form
        307308 by: Sky Gunning

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Hello List.

In the Alt section of the IMG tag below, the variable $myitem has a value of 
"Who's There".

echo "<div class='myclass'><a href='#' class='color_thumb'> <img 
src='/itemimages/$mypic' alt='$myitem' width='60' ....

When running through W3C validator, the line errors out because of the " ' " in 
"Who's".
I tried:
$myitem=(htmlentities($myitem));

But this has no affect on "Who's".

What's the best way to code this portion so the apostrophe is handled correctly?


TIA,

--Rick




--- End Message ---
--- Begin Message ---
Rick Dwyer wrote:
> Hello List.
> 
> In the Alt section of the IMG tag below, the variable $myitem has a value of 
> "Who's There".
> 
> echo "<div class='myclass'><a href='#' class='color_thumb'> <img 
> src='/itemimages/$mypic' alt='$myitem' width='60' ....
> 
> When running through W3C validator, the line errors out because of the " ' " 
> in "Who's".
> I tried:
> $myitem=(htmlentities($myitem));
> 
> But this has no affect on "Who's".
> 
> What's the best way to code this portion so the apostrophe is handled 
> correctly?
> 
> 
> TIA,
> 
> --Rick
> 
> 
> 
> 
Use it


echo '<div class="myclass"><a href="#" class="color_thumb"> <img
src="/itemimages/'.$mypic.'" alt="'.$myitem.'" width="60" ...'

--- End Message ---
--- Begin Message ---
On Tue, 2010-08-03 at 14:41 -0400, Rick Dwyer wrote:

> Hello List.
> 
> In the Alt section of the IMG tag below, the variable $myitem has a value of 
> "Who's There".
> 
> echo "<div class='myclass'><a href='#' class='color_thumb'> <img 
> src='/itemimages/$mypic' alt='$myitem' width='60' ....
> 
> When running through W3C validator, the line errors out because of the " ' " 
> in "Who's".
> I tried:
> $myitem=(htmlentities($myitem));
> 
> But this has no affect on "Who's".
> 
> What's the best way to code this portion so the apostrophe is handled 
> correctly?
> 
> 
> TIA,
> 
> --Rick
> 
> 
> 
> 


Well, because the way you're using htmlentities() there is ignoring
single quotes, i.e. not escaping them. Try myitem=htmlentities($myitem,
ENT_QUOTES); instead.

Also, as an aside, I think it's general acceptance to use double quotes
on HTML attributes rather than single. While that does make for
complications when the HTML is part of a double-quoted string in PHP, it
does avoid tricker problems surrounding Javascript event handlers on
code, which generally use single quotes when they are part of an HTML
attribute.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Rick,

Probably Sebastian's fix might work but *htmlspecialchars*  can help you,
too.

Regards,
Shreyas

On Wed, Aug 4, 2010 at 12:17 AM, Sebastian Ewert <[email protected]> wrote:

> Rick Dwyer wrote:
> > Hello List.
> >
> > In the Alt section of the IMG tag below, the variable $myitem has a value
> of "Who's There".
> >
> > echo "<div class='myclass'><a href='#' class='color_thumb'> <img
> src='/itemimages/$mypic' alt='$myitem' width='60' ....
> >
> > When running through W3C validator, the line errors out because of the "
> ' " in "Who's".
> > I tried:
> > $myitem=(htmlentities($myitem));
> >
> > But this has no affect on "Who's".
> >
> > What's the best way to code this portion so the apostrophe is handled
> correctly?
> >
> >
> > TIA,
> >
> > --Rick
> >
> >
> >
> >
> Use it
>
>
> echo '<div class="myclass"><a href="#" class="color_thumb"> <img
> src="/itemimages/'.$mypic.'" alt="'.$myitem.'" width="60" ...'
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Regards,
Shreyas Agasthya

--- End Message ---
--- Begin Message ---
On Aug 3, 2010, at 2:47 PM, Sebastian Ewert wrote:

> Rick Dwyer wrote:
>> Hello List.
>> 
>> In the Alt section of the IMG tag below, the variable $myitem has a value of 
>> "Who's There".
>> 
>> echo "<div class='myclass'><a href='#' class='color_thumb'> <img 
>> src='/itemimages/$mypic' alt='$myitem' width='60' ....
>> 
>> When running through W3C validator, the line errors out because of the " ' " 
>> in "Who's".
>> I tried:
>> $myitem=(htmlentities($myitem));
>> 
>> But this has no affect on "Who's".
>> 
>> What's the best way to code this portion so the apostrophe is handled 
>> correctly?
>> 
>> 
>> TIA,
>> 
>> --Rick
>> 
>> 
>> 
>> 
> Use it
> 
> 
> echo '<div class="myclass"><a href="#" class="color_thumb"> <img
> src="/itemimages/'.$mypic.'" alt="'.$myitem.'" width="60" ...'


Thanks Sebastian.

In the above, what is the function of the period in front of $myitem?

--Rick


--- End Message ---
--- Begin Message ---
On Tue, 2010-08-03 at 15:00 -0400, Rick Dwyer wrote:

> On Aug 3, 2010, at 2:47 PM, Sebastian Ewert wrote:
> 
> > Rick Dwyer wrote:
> >> Hello List.
> >> 
> >> In the Alt section of the IMG tag below, the variable $myitem has a value 
> >> of "Who's There".
> >> 
> >> echo "<div class='myclass'><a href='#' class='color_thumb'> <img 
> >> src='/itemimages/$mypic' alt='$myitem' width='60' ....
> >> 
> >> When running through W3C validator, the line errors out because of the " ' 
> >> " in "Who's".
> >> I tried:
> >> $myitem=(htmlentities($myitem));
> >> 
> >> But this has no affect on "Who's".
> >> 
> >> What's the best way to code this portion so the apostrophe is handled 
> >> correctly?
> >> 
> >> 
> >> TIA,
> >> 
> >> --Rick
> >> 
> >> 
> >> 
> >> 
> > Use it
> > 
> > 
> > echo '<div class="myclass"><a href="#" class="color_thumb"> <img
> > src="/itemimages/'.$mypic.'" alt="'.$myitem.'" width="60" ...'
> 
> 
> Thanks Sebastian.
> 
> In the above, what is the function of the period in front of $myitem?
> 
> --Rick
> 
> 


It is a string concatenation in PHP. But, as my last email on this
thread shows, you only need to add ENT_QUOTES to your htmlentities()
call and everything will work.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Thanks Ash... this worked.

--Rick

On Aug 3, 2010, at 3:01 PM, Ashley Sheridan wrote:

> On Tue, 2010-08-03 at 15:00 -0400, Rick Dwyer wrote:
> 
>> On Aug 3, 2010, at 2:47 PM, Sebastian Ewert wrote:
>> 
>>> Rick Dwyer wrote:
>>>> Hello List.
>>>> 
>>>> In the Alt section of the IMG tag below, the variable $myitem has a value 
>>>> of "Who's There".
>>>> 
>>>> echo "<div class='myclass'><a href='#' class='color_thumb'> <img 
>>>> src='/itemimages/$mypic' alt='$myitem' width='60' ....
>>>> 
>>>> When running through W3C validator, the line errors out because of the " ' 
>>>> " in "Who's".
>>>> I tried:
>>>> $myitem=(htmlentities($myitem));
>>>> 
>>>> But this has no affect on "Who's".
>>>> 
>>>> What's the best way to code this portion so the apostrophe is handled 
>>>> correctly?
>>>> 
>>>> 
>>>> TIA,
>>>> 
>>>> --Rick
>>>> 
>>>> 
>>>> 
>>>> 
>>> Use it
>>> 
>>> 
>>> echo '<div class="myclass"><a href="#" class="color_thumb"> <img
>>> src="/itemimages/'.$mypic.'" alt="'.$myitem.'" width="60" ...'
>> 
>> 
>> Thanks Sebastian.
>> 
>> In the above, what is the function of the period in front of $myitem?
>> 
>> --Rick
>> 
>> 
> 
> 
> It is a string concatenation in PHP. But, as my last email on this
> thread shows, you only need to add ENT_QUOTES to your htmlentities()
> call and everything will work.
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 


--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
> On Tue, 2010-08-03 at 15:00 -0400, Rick Dwyer wrote:
> 
>> On Aug 3, 2010, at 2:47 PM, Sebastian Ewert wrote:
>>
>>> Rick Dwyer wrote:
>>>> Hello List.
>>>>
>>>> In the Alt section of the IMG tag below, the variable $myitem has a value 
>>>> of "Who's There".
>>>>
>>>> echo "<div class='myclass'><a href='#' class='color_thumb'> <img 
>>>> src='/itemimages/$mypic' alt='$myitem' width='60' ....
>>>>
>>>> When running through W3C validator, the line errors out because of the " ' 
>>>> " in "Who's".
>>>> I tried:
>>>> $myitem=(htmlentities($myitem));
>>>>
>>>> But this has no affect on "Who's".
>>>>
>>>> What's the best way to code this portion so the apostrophe is handled 
>>>> correctly?
>>>>
>>>>
>>>> TIA,
>>>>
>>>> --Rick
>>>>
>>>>
>>>>
>>>>
>>> Use it
>>>
>>>
>>> echo '<div class="myclass"><a href="#" class="color_thumb"> <img
>>> src="/itemimages/'.$mypic.'" alt="'.$myitem.'" width="60" ...'
>>
>> Thanks Sebastian.
>>
>> In the above, what is the function of the period in front of $myitem?
>>
>> --Rick
>>
>>
> 
> 
> It is a string concatenation in PHP. But, as my last email on this
> thread shows, you only need to add ENT_QUOTES to your htmlentities()
> call and everything will work.
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 
> 


If you use single quotes you can't use variables inside the string. You
have to combine strings and variables or two strings with a dot.

echo 'foo'.$bar;

http://www.php.net/manual/de/language.types.string.php

I'm not shure but I think to validate xhtml you need the double quotes.

--- End Message ---
--- Begin Message ---
On Aug 3, 2010, at 3:15 PM, Sebastian Ewert wrote:

> Ashley Sheridan wrote:
>> On Tue, 2010-08-03 at 15:00 -0400, Rick Dwyer wrote:
>> 
>>> On Aug 3, 2010, at 2:47 PM, Sebastian Ewert wrote:
>>> 
>>>> Rick Dwyer wrote:
>>>>> Hello List.
>>>>> 
>>>>> In the Alt section of the IMG tag below, the variable $myitem has a value 
>>>>> of "Who's There".
>>>>> 
>>>>> echo "<div class='myclass'><a href='#' class='color_thumb'> <img 
>>>>> src='/itemimages/$mypic' alt='$myitem' width='60' ....
>>>>> 
>>>>> When running through W3C validator, the line errors out because of the " 
>>>>> ' " in "Who's".
>>>>> I tried:
>>>>> $myitem=(htmlentities($myitem));
>>>>> 
>>>>> But this has no affect on "Who's".
>>>>> 
>>>>> What's the best way to code this portion so the apostrophe is handled 
>>>>> correctly?
>>>>> 
>>>>> 
>>>>> TIA,
>>>>> 
>>>>> --Rick
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>> Use it
>>>> 
>>>> 
>>>> echo '<div class="myclass"><a href="#" class="color_thumb"> <img
>>>> src="/itemimages/'.$mypic.'" alt="'.$myitem.'" width="60" ...'
>>> 
>>> Thanks Sebastian.
>>> 
>>> In the above, what is the function of the period in front of $myitem?
>>> 
>>> --Rick
>>> 
>>> 
>> 
>> 
>> It is a string concatenation in PHP. But, as my last email on this
>> thread shows, you only need to add ENT_QUOTES to your htmlentities()
>> call and everything will work.
>> 
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>> 
>> 
>> 
> 
> 
> If you use single quotes you can't use variables inside the string. You
> have to combine strings and variables or two strings with a dot.
> 
> echo 'foo'.$bar;
> 
> http://www.php.net/manual/de/language.types.string.php
> 
> I'm not shure but I think to validate xhtml you need the double quotes.

Problem I'm having is I've inherited a PHP page that contains sections of 
PHP/Javascript/HTML/CSS all inside of a PHP echo tag.  My PHP and JS skill are 
rudimentary at best so when it comes to a block of code 40 to 50 lines in 
length, it becomes daunting to reverse the ' with ".  Each echo block starts 
with a " and the html inside uses a '.  JS also uses '.

Below is an actual block in more detail with JS in it.  Is it still recommended 
to switch with " with ' and ' with "?

--Rick


          echo "
          <p>Click on a picture to view that color:</p>";
      If (trim($pic_1) <> "") {echo "<div class='proddetailpics'><a href='#' 
class='color_thumb'> <img src='/imagedir/$pic_1' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_1',0) border='0' 
/></a></div>";}
      If (trim($pic_2) <> "") {echo "<div class='proddetailpics'><a href='#' 
class='color_thumb'> <img src='/imagedir/$pic_2' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_2',0) border='0' 
/></a></div>";}            
      If (trim($pic_3) <> "") {echo "<div class='proddetailpics'><a href='#' 
class='color_thumb'> <img src='/imagedir/$pic_3' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_3',0) border='0' 
/></a></div>";}           
      If (trim($pic_4) <> "") {echo "<div class='proddetailpics'><a href='#' 
class='color_thumb'> <img src='/imagedir/$pic_4' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_4',0) border='0' 
/></a></div>";}           
      If (trim($pic_5) <> "") {echo "<div class='proddetailpics'><a href='#' 
class='color_thumb'> <img src='/imagedir/$pic_5' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_5',0) border='0' 
/></a></div>";}          
      If (trim($pic_6) <> "") {echo "<div class='proddetailpics'><a href='#' 
class='color_thumb'> <img src='/imagedir/$pic_6' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_6',0) border='0' 
/></a></div>";}          
      If (trim($pic_7) <> "") {echo "<div class='proddetailpics'><a href='#' 
class='color_thumb'> <img src='/imagedir/$pic_7' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_7',0) border='0' 
/></a></div>";}          
      If (trim($pic_8) <> "") {echo "<div class='proddetailpics'><a href='#' 
class='color_thumb'> <img src='/imagedir/$pic_8' alt='$itemgroup $itemsubgroup' 
width='60' height='60' 
onclick=MM_swapImage('prodimage','','/imagedir/$pic_8',0) border='0' 
/></a></div>";}          
          }


--- End Message ---
--- Begin Message ---
On Tue, 2010-08-03 at 15:32 -0400, Rick Dwyer wrote:

> On Aug 3, 2010, at 3:15 PM, Sebastian Ewert wrote:
> 
> > Ashley Sheridan wrote:
> >> On Tue, 2010-08-03 at 15:00 -0400, Rick Dwyer wrote:
> >> 
> >>> On Aug 3, 2010, at 2:47 PM, Sebastian Ewert wrote:
> >>> 
> >>>> Rick Dwyer wrote:
> >>>>> Hello List.
> >>>>> 
> >>>>> In the Alt section of the IMG tag below, the variable $myitem has a 
> >>>>> value of "Who's There".
> >>>>> 
> >>>>> echo "<div class='myclass'><a href='#' class='color_thumb'> <img 
> >>>>> src='/itemimages/$mypic' alt='$myitem' width='60' ....
> >>>>> 
> >>>>> When running through W3C validator, the line errors out because of the 
> >>>>> " ' " in "Who's".
> >>>>> I tried:
> >>>>> $myitem=(htmlentities($myitem));
> >>>>> 
> >>>>> But this has no affect on "Who's".
> >>>>> 
> >>>>> What's the best way to code this portion so the apostrophe is handled 
> >>>>> correctly?
> >>>>> 
> >>>>> 
> >>>>> TIA,
> >>>>> 
> >>>>> --Rick
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>> Use it
> >>>> 
> >>>> 
> >>>> echo '<div class="myclass"><a href="#" class="color_thumb"> <img
> >>>> src="/itemimages/'.$mypic.'" alt="'.$myitem.'" width="60" ...'
> >>> 
> >>> Thanks Sebastian.
> >>> 
> >>> In the above, what is the function of the period in front of $myitem?
> >>> 
> >>> --Rick
> >>> 
> >>> 
> >> 
> >> 
> >> It is a string concatenation in PHP. But, as my last email on this
> >> thread shows, you only need to add ENT_QUOTES to your htmlentities()
> >> call and everything will work.
> >> 
> >> Thanks,
> >> Ash
> >> http://www.ashleysheridan.co.uk
> >> 
> >> 
> >> 
> > 
> > 
> > If you use single quotes you can't use variables inside the string. You
> > have to combine strings and variables or two strings with a dot.
> > 
> > echo 'foo'.$bar;
> > 
> > http://www.php.net/manual/de/language.types.string.php
> > 
> > I'm not shure but I think to validate xhtml you need the double quotes.
> 
> Problem I'm having is I've inherited a PHP page that contains sections of 
> PHP/Javascript/HTML/CSS all inside of a PHP echo tag.  My PHP and JS skill 
> are rudimentary at best so when it comes to a block of code 40 to 50 lines in 
> length, it becomes daunting to reverse the ' with ".  Each echo block starts 
> with a " and the html inside uses a '.  JS also uses '.
> 
> Below is an actual block in more detail with JS in it.  Is it still 
> recommended to switch with " with ' and ' with "?
> 
> --Rick
> 
> 
>         echo "
>         <p>Click on a picture to view that color:</p>";
>       If (trim($pic_1) <> "") {echo "<div class='proddetailpics'><a href='#' 
> class='color_thumb'> <img src='/imagedir/$pic_1' alt='$itemgroup 
> $itemsubgroup' width='60' height='60' 
> onclick=MM_swapImage('prodimage','','/imagedir/$pic_1',0) border='0' 
> /></a></div>";}
>       If (trim($pic_2) <> "") {echo "<div class='proddetailpics'><a href='#' 
> class='color_thumb'> <img src='/imagedir/$pic_2' alt='$itemgroup 
> $itemsubgroup' width='60' height='60' 
> onclick=MM_swapImage('prodimage','','/imagedir/$pic_2',0) border='0' 
> /></a></div>";}          
>       If (trim($pic_3) <> "") {echo "<div class='proddetailpics'><a href='#' 
> class='color_thumb'> <img src='/imagedir/$pic_3' alt='$itemgroup 
> $itemsubgroup' width='60' height='60' 
> onclick=MM_swapImage('prodimage','','/imagedir/$pic_3',0) border='0' 
> /></a></div>";}         
>       If (trim($pic_4) <> "") {echo "<div class='proddetailpics'><a href='#' 
> class='color_thumb'> <img src='/imagedir/$pic_4' alt='$itemgroup 
> $itemsubgroup' width='60' height='60' 
> onclick=MM_swapImage('prodimage','','/imagedir/$pic_4',0) border='0' 
> /></a></div>";}         
>       If (trim($pic_5) <> "") {echo "<div class='proddetailpics'><a href='#' 
> class='color_thumb'> <img src='/imagedir/$pic_5' alt='$itemgroup 
> $itemsubgroup' width='60' height='60' 
> onclick=MM_swapImage('prodimage','','/imagedir/$pic_5',0) border='0' 
> /></a></div>";}        
>       If (trim($pic_6) <> "") {echo "<div class='proddetailpics'><a href='#' 
> class='color_thumb'> <img src='/imagedir/$pic_6' alt='$itemgroup 
> $itemsubgroup' width='60' height='60' 
> onclick=MM_swapImage('prodimage','','/imagedir/$pic_6',0) border='0' 
> /></a></div>";}        
>       If (trim($pic_7) <> "") {echo "<div class='proddetailpics'><a href='#' 
> class='color_thumb'> <img src='/imagedir/$pic_7' alt='$itemgroup 
> $itemsubgroup' width='60' height='60' 
> onclick=MM_swapImage('prodimage','','/imagedir/$pic_7',0) border='0' 
> /></a></div>";}        
>       If (trim($pic_8) <> "") {echo "<div class='proddetailpics'><a href='#' 
> class='color_thumb'> <img src='/imagedir/$pic_8' alt='$itemgroup 
> $itemsubgroup' width='60' height='60' 
> onclick=MM_swapImage('prodimage','','/imagedir/$pic_8',0) border='0' 
> /></a></div>";}        
>         }
> 
> 


That's some damn ugly code that I'd consider putting in a loop right
away!

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Aug 3, 2010, at 3:36 PM, Ashley Sheridan wrote:

> On Tue, 2010-08-03 at 15:32 -0400, Rick Dwyer wrote:
>> 
>> On Aug 3, 2010, at 3:15 PM, Sebastian Ewert wrote:
>> 
>> > Ashley Sheridan wrote:
>> >> On Tue, 2010-08-03 at 15:00 -0400, Rick Dwyer wrote:
>> >> 
>> >>> On Aug 3, 2010, at 2:47 PM, Sebastian Ewert wrote:
>> >>> 
>> >>>> Rick Dwyer wrote:
>> >>>>> Hello List.
>> >>>>> 
>> >>>>> In the Alt section of the IMG tag below, the variable $myitem has a 
>> >>>>> value of "Who's There".
>> >>>>> 
>> >>>>> echo "<div class='myclass'><a href='#' class='color_thumb'> <img 
>> >>>>> src='/itemimages/$mypic' alt='$myitem' width='60' ....
>> >>>>> 
>> >>>>> When running through W3C validator, the line errors out because of the 
>> >>>>> " ' " in "Who's".
>> >>>>> I tried:
>> >>>>> $myitem=(htmlentities($myitem));
>> >>>>> 
>> >>>>> But this has no affect on "Who's".
>> >>>>> 
>> >>>>> What's the best way to code this portion so the apostrophe is handled 
>> >>>>> correctly?
>> >>>>> 
>> >>>>> 
>> >>>>> TIA,
>> >>>>> 
>> >>>>> --Rick
>> >>>>> 
>> >>>>> 
>> >>>>> 
>> >>>>> 
>> >>>> Use it
>> >>>> 
>> >>>> 
>> >>>> echo '<div class="myclass"><a href="#" class="color_thumb"> <img
>> >>>> src="/itemimages/'.$mypic.'" alt="'.$myitem.'" width="60" ...'
>> >>> 
>> >>> Thanks Sebastian.
>> >>> 
>> >>> In the above, what is the function of the period in front of $myitem?
>> >>> 
>> >>> --Rick
>> >>> 
>> >>> 
>> >> 
>> >> 
>> >> It is a string concatenation in PHP. But, as my last email on this
>> >> thread shows, you only need to add ENT_QUOTES to your htmlentities()
>> >> call and everything will work.
>> >> 
>> >> Thanks,
>> >> Ash
>> >> http://www.ashleysheridan.co.uk
>> >> 
>> >> 
>> >> 
>> > 
>> > 
>> > If you use single quotes you can't use variables inside the string. You
>> > have to combine strings and variables or two strings with a dot.
>> > 
>> > echo 'foo'.$bar;
>> > 
>> > http://www.php.net/manual/de/language.types.string.php
>> > 
>> > I'm not shure but I think to validate xhtml you need the double quotes.
>> 
>> Problem I'm having is I've inherited a PHP page that contains sections of 
>> PHP/Javascript/HTML/CSS all inside of a PHP echo tag.  My PHP and JS skill 
>> are rudimentary at best so when it comes to a block of code 40 to 50 lines 
>> in length, it becomes daunting to reverse the ' with ".  Each echo block 
>> starts with a " and the html inside uses a '.  JS also uses '.
>> 
>> Below is an actual block in more detail with JS in it.  Is it still 
>> recommended to switch with " with ' and ' with "?
>> 
>> --Rick
>> 
>> 
>>        echo "
>>        <p>Click on a picture to view that color:</p>";
>>       If (trim($pic_1) <> "") {echo "<div class='proddetailpics'><a href='#' 
>> class='color_thumb'> <img src='/imagedir/$pic_1' alt='$itemgroup 
>> $itemsubgroup' width='60' height='60' 
>> onclick=MM_swapImage('prodimage','','/imagedir/$pic_1',0) border='0' 
>> /></a></div>";}
>>       If (trim($pic_2) <> "") {echo "<div class='proddetailpics'><a href='#' 
>> class='color_thumb'> <img src='/imagedir/$pic_2' alt='$itemgroup 
>> $itemsubgroup' width='60' height='60' 
>> onclick=MM_swapImage('prodimage','','/imagedir/$pic_2',0) border='0' 
>> /></a></div>";}         
>>       If (trim($pic_3) <> "") {echo "<div class='proddetailpics'><a href='#' 
>> class='color_thumb'> <img src='/imagedir/$pic_3' alt='$itemgroup 
>> $itemsubgroup' width='60' height='60' 
>> onclick=MM_swapImage('prodimage','','/imagedir/$pic_3',0) border='0' 
>> /></a></div>";}        
>>       If (trim($pic_4) <> "") {echo "<div class='proddetailpics'><a href='#' 
>> class='color_thumb'> <img src='/imagedir/$pic_4' alt='$itemgroup 
>> $itemsubgroup' width='60' height='60' 
>> onclick=MM_swapImage('prodimage','','/imagedir/$pic_4',0) border='0' 
>> /></a></div>";}        
>>       If (trim($pic_5) <> "") {echo "<div class='proddetailpics'><a href='#' 
>> class='color_thumb'> <img src='/imagedir/$pic_5' alt='$itemgroup 
>> $itemsubgroup' width='60' height='60' 
>> onclick=MM_swapImage('prodimage','','/imagedir/$pic_5',0) border='0' 
>> /></a></div>";}       
>>       If (trim($pic_6) <> "") {echo "<div class='proddetailpics'><a href='#' 
>> class='color_thumb'> <img src='/imagedir/$pic_6' alt='$itemgroup 
>> $itemsubgroup' width='60' height='60' 
>> onclick=MM_swapImage('prodimage','','/imagedir/$pic_6',0) border='0' 
>> /></a></div>";}       
>>       If (trim($pic_7) <> "") {echo "<div class='proddetailpics'><a href='#' 
>> class='color_thumb'> <img src='/imagedir/$pic_7' alt='$itemgroup 
>> $itemsubgroup' width='60' height='60' 
>> onclick=MM_swapImage('prodimage','','/imagedir/$pic_7',0) border='0' 
>> /></a></div>";}       
>>       If (trim($pic_8) <> "") {echo "<div class='proddetailpics'><a href='#' 
>> class='color_thumb'> <img src='/imagedir/$pic_8' alt='$itemgroup 
>> $itemsubgroup' width='60' height='60' 
>> onclick=MM_swapImage('prodimage','','/imagedir/$pic_8',0) border='0' 
>> /></a></div>";}       
>>        }
>> 
>> 
> 
> That's some damn ugly code that I'd consider putting in a loop right away!

The whole page is like this.... that's why I said it was daunting : (

--- End Message ---
--- Begin Message ---
Hello

I think your code would be very nice to be able to hep you out or correct
your methods.

On Tue, Aug 3, 2010 at 1:33 AM, David Mehler <[email protected]> wrote:

> Hello,
> Not sure if this went out, apologies if this is a double post.
> I'm having difficulty tying something together. I'm wanting to display
> a record from a database in a form, information from the various
> fields in the database goes in to their coresponding fields in the
> form, for example address field of the database goes in to the address
> field of the form etc. If I then edit and resubmit that same form the
> field or fields edited and only them will be updated. I'd like this to
> be all in one file.
>

You mean all you php + html code in the same file ?


> This tells me I need three queries, one a method to display records
> for selection and editing which I have, the second to select the
> specific record based on the ID in this case and to put that in the
> form which isn't working the form display part, and the third to
> update any altered fields which I don't have.
>

>From what i gather, you will need 2 query's : 1 select and 1 update.
Dont understand what that third one does.

If anyone has code like this i'd appreciate it.
> Thanks.
> Dave. <http://www.php.net/unsub.php>
>
>
here is a quick and dirty example :

<?php
$id = (int)$_GET['id'];

$requete = "SELECT * FROM Users WHERE id='$id'";
$sql = mysql_query($requete);
$user = mysql_fetch_assoc($sql);


if(!$_POST)
{
    echo '
    <form action="" method="post">

        <h3>Email</h3>
        <p><input type="text" name="email"
value="'.htmlentities($user['email']).'" /></p>

        <h3>Login</h3>
        <p><input type="text" name="login"
value="'.htmlentities($user['login']).'" /></p>

        <h3>Mot de passe</h3>
        <p><input type="text" name="password"
value="'.htmlentities($user['password']).'" /></p>

    </form>';
}
else
{

    $login = mysql_real_escape_string($_POST['login']);
    $email = mysql_real_escape_string($_POST['email']);
    $password = mysql_real_escape_string($_POST['password']);

    $requete = "UPDATE Users SET login='$login', email='$email',
password='$password'";
    mysql_query($requete);

}
?>


You can make this much better by getting the fields list from the database
before displaying the form, then display the form according to fields
informations.
The update can also be much better like building the update query according
to the POST array and confirming the each key with the table fields.


Sry if i did not understand you right.


Sky_G

--- End Message ---

Reply via email to