Jump to content

Newbie question - updating SQL from drop down menu


emailuser

Recommended Posts

Hi , i am very new to php and am trying to change a php asset program to include another drop down menu ,

I have created the drop down and it shows the correct entries from Audit in sql , the process is that the user completes the php form for a new asset then clicks save to enter it to the database , the details below adds another drop down menu once they have selected the correct value i do not know how to capture this and write it back to the sql database ... help much appreciated ...

 

// $sql = 'SELECT * FROM audit';

// $res = mysql_query($sql) or die(mysql_error());

// while ($rec = mysql_fetch_assoc($res)) $desc[] = $rec;

 

  // die('<pre>'.print_r($desc));

 

// echo '<SELECT name="dropdown">';

// foreach ($desc as $c)

// {

//  if ($c['id'] == $_GET['id'])

  //    echo "<OPTION value=\"{$c['id']}\" SELECTED>{$c['desc']}</OPTION>\n";

  //  else

  //    echo "<OPTION value=\"{$c['id']}\">{$c['desc']}</OPTION>\n";

// }

// echo '</SELECT>';

Link to comment
Share on other sites

You either need to do one of the following two:

1) An ajax call to update the database and then use javascript to add another populated dropdown (tricky)

2) Perform a "submit" and reload the same page after having parsed the information through PHP (preferred for your level)

Link to comment
Share on other sites

If I have caught the right meaning, it's pretty simple actually, in php.

 

switch:

<?php

switch($dropdown)
case "a" :
      return /*sql statement*/ ;
case "b" :
      return /*sql statement*/ ;
case "c" :
      return /*sql statement*/ ;
?>

etc..

 

If I understood, that should work; if I got the wrong drift, please tell me.

 

Sam

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.