genscythe Posted March 12, 2006 Share Posted March 12, 2006 I'm having problems with my queries from my drop down lists to my DB.I use the following codes to populate my drop down lists with data retrieved from my MySQL DB.[code]print "<select name=myselect2>"; print "<option value=none> [none selected] </option>"; while($row = mysql_fetch_row($result)) { $value = "$row[0]"; print "<option value=$value> $value </option>"; } print "</select>";[/code]Then having selected a selection from the list, I use it in my select and insert statements:[code]$myselect2 = trim($_POST['myselect2']);if ($myselect2 == "none") { $refPersonID = ' '; } else { $query_reference = "select client_id from client where name = '$myselect2'"; $result_reference = mysql_query($query_reference) or die ("Error in query: $query_reference. " . mysql_error()); while($row = mysql_fetch_row($result_reference)) { $refPersonID = "$row[0]"; } }$query_client = "insert into Client (name, address, reference_person_id, tel_no, mobile_no) values ('$cName', '$add', '$refPersonID', '$tNo', '$mNo')"; $result_client = mysql_query($query_client) or die ("Error in query: $query_client. " . mysql_error());[/code]*$refPersonID should be an integer*reference_person_id can be NULLI always encounter two problems here. The first is that with any selection I choose, it seems that it doesn't seem to get the value of the selected option. The second is that even if i want my value to be NULL, my DB doesn't accept my query. Instead it errors:[b]Error in query: insert into Client (name, address, reference_person_id, tel_no, mobile_no) values ('Pao Santos', '123 Jess St.', '', '7215487', '9186549874'). Out of range value adjusted for column 'Reference_Person_ID' at row 1[/b]Can anyone help me with this? Quote Link to comment https://forums.phpfreaks.com/topic/4766-problems-with-queries-from-dropdown-lists/ Share on other sites More sharing options...
keeB Posted March 12, 2006 Share Posted March 12, 2006 [!--quoteo(post=354244:date=Mar 12 2006, 06:24 PM:name=genscythe)--][div class=\'quotetop\']QUOTE(genscythe @ Mar 12 2006, 06:24 PM) [snapback]354244[/snapback][/div][div class=\'quotemain\'][!--quotec--]I'm having problems with my queries from my drop down lists to my DB.I use the following codes to populate my drop down lists with data retrieved from my MySQL DB.[code]print "<select name=myselect2>"; print "<option value=none> [none selected] </option>"; while($row = mysql_fetch_row($result)) { $value = "$row[0]"; print "<option value=$value> $value </option>"; } print "</select>";[/code]Then having selected a selection from the list, I use it in my select and insert statements:[code]$myselect2 = trim($_POST['myselect2']);if ($myselect2 == "none") { $refPersonID = ' '; } else { $query_reference = "select client_id from client where name = '$myselect2'"; $result_reference = mysql_query($query_reference) or die ("Error in query: $query_reference. " . mysql_error()); while($row = mysql_fetch_row($result_reference)) { $refPersonID = "$row[0]"; } }$query_client = "insert into Client (name, address, reference_person_id, tel_no, mobile_no) values ('$cName', '$add', '$refPersonID', '$tNo', '$mNo')"; $result_client = mysql_query($query_client) or die ("Error in query: $query_client. " . mysql_error());[/code]*$refPersonID should be an integer*reference_person_id can be NULLI always encounter two problems here. The first is that with any selection I choose, it seems that it doesn't seem to get the value of the selected option. The second is that even if i want my value to be NULL, my DB doesn't accept my query. Instead it errors:[b]Error in query: insert into Client (name, address, reference_person_id, tel_no, mobile_no) values ('Pao Santos', '123 Jess St.', '', '7215487', '9186549874'). Out of range value adjusted for column 'Reference_Person_ID' at row 1[/b]Can anyone help me with this?[/quote]It looks like the field definition of reference_person_id is too small.. make it bigger [= Quote Link to comment https://forums.phpfreaks.com/topic/4766-problems-with-queries-from-dropdown-lists/#findComment-16756 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.