single and double quotes problem – PHP

  php

Q(Question):

i have values like
alias = Indus International School"In omnia paratus", meaning "Prepared for all challenges"
model = "In omnia paratus", meaning "Prepared for all challenges"

$myresult .= "<a href=\"Schools/".$_row['alias']."\"><img src=\"/school/schoolpicdisplay.php?p1=".$brand."&p2=".$row['model']." \" width=\"50\" height=\"80\"></img></a>";

when i try to print the alias and model values are not coming . what the work arounf for it . I have used mysql_real_escape_string while inserting to DB. what must be done while printing or after taking out of db.

A(Answer):

use single quotes for html attributes?


$result = "<a href='{$row['alias']}'><img src='/school/schoolpicdisplay.php?p1={$brand}&pd={$row['model']}' width='50' height='80' /></img></a>"

Dan

A(Answer):

That worked
whats the actual problem in the way i used ?

whts the difference b/w if i use {$model} or ".$model." will it make any difference ?

Now its giving problems for the single quotes thing like

model = Sri Kumaran Children’s Home

its not printing completely its printing till Sri Kumaran Children the url looks like

$myresult .= "<a href='Schools/{$alias}'><img src='/school/schoolpicdisplay.php?p1={$brand}&p2={$model}' width=\"50\" height=\"80\"></img></a>";

A(Answer):

how to handle the single quote problem ?

A(Answer):

use url_encode().

Dan

A(Answer):

yeah i used rawurlencode . i learnt 2 main thing by this question .

1. to encode the variable when passing through the urls

2. to use mysql_real_escape_string when using the variable in a mysql statement .

any things else important i have left out while handling quotes ?

A(Answer):

i solved tht quotes problem with the rawurlencode . but i am facing another problem. like
the alias has value like $alias = "Sony DSC-TX1/H"
when i am making it an url like

<a href="<?php echo ucfirst($value).'/'.rawurlencode($row1['alias']); ?>"><?php echo $row1['property1']; echo " ";echo $row1['property2'] ?></a>

its leading to a page not found like
The requested URL /Cameras/SonyDSC-TX1/H was not found on this server.
the / is making a prob .will the rawurlencode take care of slash?

http://122.166.8.199/Cameras/SonyDSC-TX1%2FH

LEAVE A COMMENT