problems dealing with select box

They have: 164 posts

Joined: Nov 2001

i have a function that display select box. i used this function 3 times to display 3 select box.

my problem is, i can't seem to insert values into the database. i only managed to insert the first select box, and the rest of the select box remain empty.

this is my function:

<?php
function job($name)
{
   
    echo \
"<select name=$name style=\\"font-family: Verdana; font-size: 8pt\\">\";
    echo \"<option \";
    if (
$job == '')
        echo \"selected\";
    echo \">\";

    echo \"<option value=database \";
    if (
$job == 'database')
        echo \"selected\";
    echo \" >Database Administrator\";

    echo \"<option value=hardware \";
    if (
$job == 'hardware')
        echo \"selected\";
    echo \" >Hardware Engineer\";

    echo \"<option value=helpdesk \";
    if (
$job == 'helpdesk')
        echo \"selected\";
    echo \" >Helpdesk Support\";

    echo \"<option value=programmer \";
    if (
$job == 'programmer')
        echo \"selected\";
    echo \" >Programmer\";

    echo \"<option value=projmanager \";
    if (
$job == 'projmanager')
        echo \"selected\";
    echo \" >Project Manager\";

    echo \"<option value=sysadm \";
    if (
$job == 'sysadm')
        echo \"selected\";
    echo \" >System Administrator\";

    echo \"<option value=syseng \";
    if (
$job == 'syseng')
        echo \"selected\";
    echo \" >System Engineer\";

    echo \"<option value=webdev \";
    if (
$job == 'webdev')
        echo \"selected\";
    echo \" >Web Developer\";

    echo \"</option>\";
    echo \"</select>\";
   
}
?>

this is the way i called the function:

<?php
echo \"<table border=0 width=100% cellpadding=0 cellspacing=0>\";
    echo \"<tr><td width=30
?>
\";
echo \"Job specializations you are interested in:font>\";
echo \"\";
job(job);
echo \"\";
job(job1);
echo \"\";
job(job2);

echo \"\";

?>

this is how i insert:

<?php
$sql_up
= mysql_query(\"update biopersonal set job='$job', job1='$job1', job2='$job2' where uname='$uname'\");
?>

what is wrong with my code?? pls help!!

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

try with quotes...
job("job2");

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

try this on for size...

<?php
function job($name, $selected)
{
   
   
$job_list = array(
                   
// value, name
                   
array('', ''), // blank first line
                   
array('database', 'Database Administrator'),
                    array(
'hardware', 'Hardware Engineer'),
                    array(
'helpdesk', 'Helpdesk Support'),
                    array(
'programmer', 'Programmer'),
                    array(
'sysadm', 'System Administrator'),
                    array(
'syseng', 'System Engineer'),
                    array(
'webdev', 'Web Developer')
                    );
   
    echo \
"<select name=\\"$name\\" style=\\"font-family: Verdana; font-size: 8pt\\">\n\";
   
    foreach (
$job_list as list($value, $text)) {
       
$tmp = ($selected == $value) ? 'SELECTED' : '';
        echo \"<option value=\\"
$value\\" $tmp>$text</option>\n\";
    }
   
    echo \"</select>\";
   
}
?>
<?php
echo \"<table border=0 width=100% cellpadding=0 cellspacing=0>\";
echo \"<tr><td width=30
?>
\";
echo \"Job specializations you are interested in:font>\";
echo \"\";
job(\"job\", $job);
echo \"\";
job(\"job1\", $job1);
echo \"\";
job(\"job2\", $job2);
echo \"\";

?>BTW, I like your code... did you read the PEAR coding standards?

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 164 posts

Joined: Nov 2001

hmm...i'm getting this error...

Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /usr/local/plesk/apache/vhosts/certifyexpress.com/httpdocs/phpresume/index.php on line 244
'

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.