Jump to content

second onchange submit form


Go to solution Solved by Gazz1982,

Recommended Posts

Hi, I'm using the below code for a list, I want to do this again for a second query (drop down), on the same page

eg. using:

$sql2="SELECT statement2"

$result2=mysql_query($sql2);

 

I have tried renaming the variables but it just leads to a blank screen, where have I gone wrong? Thanks.

...
$sql1="SELECT Questions.Question_ID, Questions.Question from Questions ORDER BY `Questions`.`Question_ID` ASC";
$result1=mysql_query($sql1);

$site_array = array();

while (list($id, $name) = mysql_fetch_row($result1)) {$site_array[$id] = $name;}

function get_options($arr, $current=null) 
{
    $opts = '';
    foreach ($arr as $k => $v) {
        $sel = $k==$current ? 'selected="selected"' : '';
        $opts .= "<option value='$k'  $sel>$k          $v</option>\n";
    }
    return $opts;
}
...


...
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  <select name="site" onchange="this.form.submit();">
<?php echo"<option>Select Question</option>";?>
    <?php echo get_options($site_array);?>
  </select>
</form>
...

The above code does exactly what I want it to do, I duplicated the code as follows:

$aspect_array = array();

while (list($id2, $name2) = mysql_fetch_row($result2)) {$aspect_array[$id2] = $name2;}

function get_options($arr2, $current2=null) 
{
    $opts2 = '';
    foreach ($arr2 as $k2 => $v2) {
        $sel2 = $k2==$current2 ? 'selected="selected"' : '';
        $opts2 .= "<option value='$k2'  $sel2>$k2          $v2</option>\n";
    }
    return $opts2;
}
...

...
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  <select name="aspect" onchange="this.form.submit();">
<?php echo"<option>Select Aspect</option>";?>
    <?php echo get_options($aspect_array);?>
  </select>
</form>
...
Edited by Gazz1982
Link to comment
https://forums.phpfreaks.com/topic/299537-second-onchange-submit-form/
Share on other sites

Is PHP set to show all errors and warnings? To make sure, you can add the following to the top of your script during the debugging process:

error_reporting(E_ALL);
ini_set('display_errors', 1);
 
Side note: using the raw value from PHP_SELF in the form action attribute makes your script vulnerable to XSS attacks. To send form submissions to the same page, you can leave the attribute blank or delete the attribute altogether.
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.