Page 1 of 1

[noob] inserting value from dropdown list was cut-off

Posted: Tue Aug 12, 2008 5:39 pm
by GuitarCoder
im writing a SQL statement to write a value from a dropdown to the database but only the 'first word' is written...

- the data is from table1... i created a function for a dropdown list of a column (ex: States - new jersey)

Code: Select all

 
function generate_titles($conn){
$titles="";
 
$query = "SELECT cState FROM tblState";
 
$result = odbc_exec($conn, $query);
 
    while ($return = odbc_fetch_array($result)){ 
        $titles.="<option value= $return[cState]>".$return[cState]."</option>";
    }
    return $titles;
}
 

- the column display correctly as dropdown list...
- now, im trying to write it to table2 but only 'new' (instead of new jersey) is written to the database

Code: Select all

 
$query="INSERT INTO tbl2(sName, sAddress, sState, sCountry) 
    VALUES ('".$NewName."','".$NewAddress."','".$NewState."','".$NewScountry."')";
 
$result_insert = odbc_exec($db, $query);
 

any ideas? thanks! :banghead:

Re: [noob] inserting value from dropdown list was cut-off

Posted: Tue Aug 12, 2008 6:12 pm
by califdon
Enclose your array keys in single quotes:

Code: Select all

$titles.="<option value=". $return['cState'].">".$return['cState']."</option>";