You are here: Re: Challenge: MySql result to drop down box « All PHP « IT news, forums, messages
Re: Challenge: MySql result to drop down box

Posted by Rik on 07/13/06 21:10

shubeer wrote:
> Here's how I would have written the code to build the select box:
>
> <?php
> $res=mysql_query("SELECT DISTINCT job_name AS JOB_NAME FROM
> oats_jobs_users_laborCode where user='$username' order by job_name")
> or die('Query failed');
>
> echo "<select name='jobname'><option SELECTED='SELECTED'>Choose
> One</option>";
> foreach($row as mysql_fetch_assoc($res)) {
> echo "<option value='{$row[JOB_NAME]}'>{$row[JOB_NAME]}</option>";
> }
> echo "</select>";


Which will give an E_NOTICE error.
Use {$row['JOB_NAME']}.

> also, make sure that the $username variable doesn't have a quote (')
> in it or the query will fail


Yup, mysql_real_escape_string() it.

Grtz,
--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация