Jump to content

problems with queries from dropdown lists


genscythe

Recommended Posts

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 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?
Link to comment
Share on other sites

[!--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 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?
[/quote]


It looks like the field definition of reference_person_id is too small.. make it bigger [=
Link to comment
Share on other sites

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.