genscythe
-
Posts
1 -
Joined
-
Last visited
Never
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.
problems with queries from dropdown lists
in PHP Coding Help
Posted
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 NULL
I 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?