Jump to content

help with unexplained output, dropdown list


Darkmatter5

Recommended Posts

Here's my textbox code

<input name="surveys" type="text" tabindex="10" />

 

Here's my dropdown list code

<?php
  include 'library/dbconfig.php';
  include 'library/opendb.php';

  $query="SELECT county_id, county
              FROM byrnjobdb.counties
              ORDER BY county ASC";
  $result=mysql_query($query);
  echo "<select id='surveys_county' method='get' tabindex='12'>";
  echo "<option>---Select---</option>";
  while ($row=mysql_fetch_array($result)) {
    $r1=$row['county_id'];
    $r2=$row['county'];
    echo "<option value='$r1'>$r2</option>";
  }
  echo "</select>";

  include 'library/closedb.php';
?>

 

Here's the submissions button code

<input name="addsurvey" type="submit" id="addsurvey" value="Submit new data" tabindex="11" />

 

Here's the code executed when the button is pressed

<?php
  if(isset($_POST['addsurvey'])) {
  include 'library/dbconfig.php';
  include 'library/opendb.php';

  //insert data into table
  $insertdata="INSERT INTO byrnjobdb.surveys (survey, county_id) VALUES ('" .$_POST['surveys']. "', '" .$_POST['surveys_county']. "')";
  /*mysql_query($insertdata) or die(mysql_error() .": $insertdata");
  echo $_POST[$survey]. " ADDED to surveys table...";*/
  echo "surveys: " .$_POST['surveys']. "<br>";
  echo "county: " .$_POST['surveys_county'];

  include 'library/closedb.php';
  }
?>

 

Now when I run the code I get the output of:

 

surveys: xxxx

county:

 

Why does it not output:

 

surveys: xxx

county: 2

 

or whatever county ID the user selects.  And yes the counties table is populated with counties, it's not empty.  Any ideas?

You're problem is occurring because the form is being sent via the GET method and you are checking the $_POST array. Either check the $_GET array or change

<?php
echo "<select id='surveys_county' method='get' tabindex='12'>";
?>

to

<?php
echo "<select id='surveys_county' method='post' tabindex='12'>";
?>

 

Ken

I did the following and it's still giving me the same output.  I only changed the dropdown list.

<?php
  include 'library/dbconfig.php';
  include 'library/opendb.php';

  $query="SELECT county_id, county
              FROM byrnjobdb.counties
              ORDER BY county ASC";
  $result=mysql_query($query);
  echo "<select id='surveys_county' method='post' tabindex='12'>";
  echo "<option>---Select---</option>";
  while ($row=mysql_fetch_array($result)) {
    $r1=$row['county_id'];
    $r2=$row['county'];
    echo "<option value='$r1'>$r2</option>";
  }
  echo "</select>";

  include 'library/closedb.php';
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.