php - Dropdown menu with values from DB -


i want create dropdown menu called "rooms" shows me available rooms stored in database.

the index.php shows table devices , name of room in device stored. (sql query: select deviceid, devicename, roomname device left join room on device.roomid = room.roomid) roomid being primary key in room-table , device.roomid foreign key in device-table.

the user should able change device's room, did link next each device redirects me form. in form want dropdown menu show current room default value, , available rooms options.

$sql1 = "select roomname device left join room on device.roomid = room.roomid deviceid='$id'";  $sql7 = "select distinct roomname, roomid room";  require_once ('config.php');  $db_link = mysqli_connect (mysql_host,                              mysql_user,                              mysql_pw,                              mysql_database);          mysqli_set_charset($db_link, 'utf8');       $db_erg = mysqli_query( $db_link, $sql1 );       if ( ! $db_erg )  {    die('error: ' . mysqli_error($db_link));  }  $db_erg2 = mysqli_query( $db_link, $sql7);  echo 'room:';  echo '</br>';  echo '</br>';  echo '<select name="room>';    while($row = mysqli_fetch_array($db_erg2, mysql_assoc))   {    echo '<option value="' . $row['roomid'] .'"selected="selected">' . $row['roomname'] . '</option>';  }    while($row = mysqli_fetch_array($db_erg, mysql_assoc))   {    echo '<option value="' . $row['roomid'] . '">' . $row['roomname'] . '</option>';        }

i added button creates sql query update device table new roomid. roomid passed query when change room in dropdown menu. if not, sql-query this: "update device blaabala set device.roomid = ""; , blank roomid leads "cannot add or update child row: foreign key constraint fails"

and want passed when dont change room (i have mention here room later contain boxes , when change boxes dont want have change room everytime well.)

hope understands problem since english ain't mothertongue. in advance

<option value="<?=$row['roomid']?>"> <?=$row['roomname']?></option> 
  1. query error

    its because have referential integrity enforced , violating it. trying add or update record using invalid foreign key(key not exist).


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -