/    Sign up×
Community /Pin to ProfileBookmark

Updating multiple database records via Two Listboxes

Hello everybody,

I have two listbox called availableValues and selectedValues.I can add multiple values and view them and it works fine.Now when i click on the edit button on my form i get the listboxes filled with their values respectively from the DB.And this works fine.Now my problem is how can i update the selectedValues listbox, when i remove or add values in it.please help i am desperate to make this work.i will appreciate your time and help.

the database sturture is like this

TABLE `groups` (
`groupID` int(10) unsigned NOT NULL auto_increment,
`interface` varchar(8) default NULL,
`groupname` varchar(45) default NULL,
PRIMARY KEY (`groupID`)
)

TABLE `group_members` (
`groupMemberID` int(10) unsigned NOT NULL auto_increment,
`groupID` int(10) default NULL,
`hostID` int(10) default NULL,
PRIMARY KEY (`groupMemberID`)
)

CREATE TABLE `host` (
`hostID` int(10) unsigned NOT NULL auto_increment,
`name` varchar(45) default NULL,
`user_id` int(10) unsigned NOT NULL default ‘0’,
PRIMARY KEY (`hostID`)
)

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@pointfiftyaeNov 09.2005 — Could you post some html/php code please?
Copy linkTweet thisAlerts:
@zolfauthorNov 10.2005 — Hi there,

Here is the code,hope you can figure out the code.

cheers

zolf

<?php session_start();?>

<?php

require_once("class.host.php");

require_once("elements.php");

("Location: index.php");

?>

<?php

$userid = $_SESSION['user_id'];

$ohost = new host;

$face = $_
GET["interface"];

$op = $_GET["action"];*/

if (isset($_
SESSION['valid_user']))

{

$user = $_SESSION['valid_user'];

$userid = $_
SESSION['user_id'];

$ohost = new host;

$face = $_GET["interface"];

$op = $_
GET["action"];

// check for http post vars

if ($_POST)

{

//echo "INSIDE POST";

if(array_key_exists('select', $_
POST))

{

//print_r($_POST['select']);

$hostname = $_
POST['select'];

//print_r($value);

//echo $value[1];

//print_r($v);

}

$groupname = $_POST["groupname"];

$interface = $face;



$FORMOK = true;

if ($FORMOK)

{

$op = $_GET["action"];

$aArgs["interface"] = strtoupper($interface);

$aArgs["groupname"] = strtolower($groupname);

if (!strcmp("add", $op))

{

($hostname,$userid);

$FORMOK = $ohost->addGroup($aArgs,$hostname,$userid);

//exit;

}

elseif (!strcmp("edit", $op))

{

$id = $_
GET["id"];

}

if ($FORMOK)

{

if(!strcmp("INTERNAL", $interface))

{

header("Location: viewgroups.php?action=int");

}

else

{

header("Location: viewgroups.php?action=int");

}

$hInterface = null;

$hAddr = null;

$hIPAddr = null;

$hNetmask = null;

}

}//IF

}//IF

else

{

$op = $_GET["action"];

$interface = $_
GET["interface"];

//echo "INSIDE ELSE";

if (!strcmp("add", $op))

{

$hInterface = $interface;

$hAddr = null;

$hIPAddr = null;

$hNetmask = null;

}

elseif (!strcmp("edit", $op))

{

$groupid = $_GET["id"];

}//IF

elseif (!strcmp("del", $op))

{

$id = $_
GET["id"];

$FORMOK = $ohost->deleteHost($id);

if ($FORMOK)

{

//echo $face;

if(!strcmp("Internal", $face))

{

header("Location: viewhost.php?action=int");

}

else

{

header("Location: viewhost.php?action=ext");

}

//header("Location: viewhost.php?action=int");

$hInterface = null;

$hAddr = null;

$hIPAddr = null;

$hNetmask = null;

}

}//IF

else

{

//header("Location: view_host.php");

$hInterface = null;

$hAddr = null;

$hIPAddr = null;

$hNetmask = null;

}

}//ELSE

}//IF

else

{

header("Location: log.php");

}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>DHCP</title>

</head>

<BODY onLoad="createListObjects()">

<div id="maincontent">

<TABLE border=1 width=100% height=100% align=center cellpadding=2 cellspacing=0>

<TR valign=middle><TD>

<TABLE cellPadding=6 cellSpacing=1 width=450 NOWRAP align=center bgcolor=#D5EAFF>

<form action="" method="POST" onSubmit="selectAll()">

<TR bgcolor=#D5EAFF>

<TD align=center><b>Edit Address Group</b></TD></TR>

<!--<TR bgcolor=#D5EAFF><td><b>&nbsp;&nbsp;Interface:&nbsp;&nbsp;&nbsp;wan1</b></td></tr>-->

<TR bgcolor=#D5EAFF>

<TD align=left><B>&nbsp;&nbsp;Group Name:&nbsp;&nbsp;&nbsp;</B>

<INPUT type=text name = groupname value="">

</TD>

</TR>

<TR bgcolor=#D5EAFF><TD align=center>

<TABLE border=0 cellspacing=5 width=400>

<TR><TD width=45%>Available Addresses:</TD>

<TD width=10% ></TD>

<TD width=45%>Members:</TD>

</TR>

<TR><TD>

<?

require_once("..classesclass.Listbox.php");

require_once("..classesclass.Listboxe.php");

//echo $face;

$op = $_GET["action"];

//echo("<h3>Class ComboBox Demo </h3>");

if (!strcmp("INTERNAL", $face))

{

if(!strcmp("edit", $op))

{

$MakeListBox = new Listboxe("host", "firewall","internal",$userid,$groupid);

}

else

{

$MakeListBox = new Listbox("host", "firewall","internal",$userid);

}

}

else

{

if(!strcmp("edit", $op))

{

$MakeListBox = new Listboxe("host", "firewall","external",$userid,$groupid);

}

else

{

$MakeListBox = new Listbox("host", "firewall","external",$userid);

}

}

?>

</TD>

<TD valign=middle>

<button onClick="addAll()">&gt;&gt;&gt;</button>

<br>

<button onClick="addAttribute()">&gt;</button>

<br>

<br>

<button onClick="delAttribute()">&lt;</button>

<br>

<button onClick="delAll()">&lt;&lt;&lt;</button>

</TD>

<TD>

<?php

require_once("..classesclass.ListboxSelected.php");

if(!strcmp("edit", $op))

{

$MakeListBox = new ListboxSelected("host", "firewall","internal",$userid,$groupid);

}

else{ ?>

<select name="select[]" size="6" multiple>

</select>

<?php } ?>

</TD>

</TR>

</TABLE>

</TD></TR>

<TR bgcolor=#D5EAFF>

<TD align=center >

<input type="submit" name="Submit" value="Submit">

<!--<button onClick="showSelected()">Submit</button>-->

</TD></TR>

</form>

</TABLE>

</TD></TR>

</TABLE>

</SCRIPT>

<script language="javascript">

var objContainer;

var objTmp;

objContainer = createContainer();

//XPPanelbarCss

setTheme("../../../../../XPPanelbar/Css/XPBlue.css", null, null)

objContainer.render(150);

</script>

<script language="javascript">

function selectAll() {

var listB = document.getElementById( "select[]" );

for( var i = 0; i < listB.length; i++ ) {

listB[i].selected = true;

}

return true;

}

</script>

</div>

</body>

</html>
Copy linkTweet thisAlerts:
@SheldonNov 10.2005 — can you edit it so that it is in [ php ] code [ /php ] tags please
Copy linkTweet thisAlerts:
@zolfauthorNov 13.2005 — Thanks everybody!!!

I figured out the problem.

cheers

zolf
Copy linkTweet thisAlerts:
@purefanNov 13.2005 — still you could post it just for the sake of future "help-wanted"s
Copy linkTweet thisAlerts:
@zolfauthorNov 14.2005 — Hi everybody,

In short, I first get the groupID of the selected values and delete it from the group_member table.then i again add the new selected values into the table.

since to do this i have a lot of code on different pages to do this.it is not possible to post all the code here.But I am happy to help regarding this topic.

cheers

zolf
×

Success!

Help @zolf spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...