Tying to use php variable in sql select statement -


i'm new php , i'm combining 2 pieces of code has been written others. page displays records mysql database , variable i'm trying use being displayed using following code:

<span class="headleft"><?php echo cleandata($this->recipe->name); ?>:</span> 

the sql select statement trying use name field it's lookup.

select    name   , round(sum(i.calories)/1500*100,2) calories   , round(sum(protein)/525*100,2) protein   , round(sum(fat)/300*100,2) fat   , round(sum(carbohydrate)/675*100,2) carbohydrate   , round(sum(fiber)/30*100,2) fiber   , round(sum(sugar)/375*100,2) sugar   , round(sum(saturated_fat)/150*100,2) saturated_fat   , round(sum(monounsaturated_fat)/150*2,2) monsaturated_fat   , round(sum(polyunsaturated_fat)/150*2,2) polyunsaturated_fat   , round(sum(cholesterol)/200*100,2) cholesterol   , round(sum(sodium)/1300*100,2) sodium   `mr_recipes` r    left join ingredients on r.id = i.recipeid     name = ($this->recipe->name) group name 

i can't quite variable work. can't use $name , i've tried wrapping in single , double quotes. if need entire page code, supply it. in advance.

take prepared statements. prevent sql injections, not concatenate sql query , parameters.

you should use pdo it's safer.

here similar issue.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -