Jump to content


Photo

problems with queries from dropdown lists


  • Please log in to reply
1 reply to this topic

#1 genscythe

genscythe
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 12 March 2006 - 06:24 PM

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.

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

Then having selected a selection from the list, I use it in my select and insert statements:

$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());

*$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:

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

Can anyone help me with this?

#2 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 12 March 2006 - 07:56 PM

[!--quoteo(post=354244:date=Mar 12 2006, 06:24 PM:name=genscythe)--][div class=\'quotetop\']QUOTE(genscythe @ Mar 12 2006, 06:24 PM) View Post[/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.

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

Then having selected a selection from the list, I use it in my select and insert statements:

$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());

*$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:

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

Can anyone help me with this?
[/quote]


It looks like the field definition of reference_person_id is too small.. make it bigger [=

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users