Jump to content

Recommended Posts

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)

 

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

 

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

$result_insert = odbc_exec($db, $query);

 

 

any ideas? thanks!  :'(

Link to comment
https://forums.phpfreaks.com/topic/119401-noob-data-is-cut-off-after-sql-insert/
Share on other sites

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;
}

 

You need to put quotes around the option value. If you dont put the quotes and there is a space in the value, only the first word will be set to the value. Like in your case, only 'new was set to the value rather then 'new jersey'

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.