Hi,
I have given my code below. The logic is:
- Display all Users details who have enrolled for access to my web page (default value for authorization is zero) on clicking 'NEW USERS'
- For those records where check boxes checked authorization will be updated to 1 (access given) on clicking 'AUTHORIZE' button
- For those records where check boxes checked will be deleted from the Users table (access denied) on clicking 'REJECT' button (this line is commented in code)

I want to have 2 submit type buttons in a form calling 2 different functions from my library file. I tried my level best but couldn't succeed. Given my code with insert function (insuser) only working; Can anyone help me in enabling REJECT button also in the same form.

Attachment contains the main code and the function from library.

Simply check for button is set or not..

if (isset($_POST['Authorize']))
{
global $iusers;
       	if(empty($_POST['checkbox']))
	{
		echo "No record has been checked ....";
		exit;
	}
	else
	{		
		$matchstring = "";
		$ispresent = 0;
		foreach ($_POST['checkbox'] as $v)
		 	{
				$ispresent = 1;
				$ins_id = mysql_real_escape_string($v); 
				$matchstring = $matchstring.","."'".$ins_id."'";
		 	}
		if ($ispresent == 1)
		{
			$matchstring = substr($matchstring,1);
			$sql="update users set authorize=1 where name in (".$matchstring.")";
                        $result=mysql_query($sql) or die ('Authorization failed.'.mysql_error());
			echo "Successfully authorized";
			madmin();
		}
		else
		{
			echo "No Records to Authorize";
		}

	}
}

if (isset($_POST['Reject']))
{
// use  your code
}

Hope it helps you

mvsjs original code

<?php
include('../library/dbconnect.php');  // Here you include dbconnect php
?>
<body>
<table width=100%>

<form name="form1" method="post" action="madmin.php?iuser=1">

<tr>
<div class="ubercolortabs">
<ul>
<li class-"selected"><a href="mainindex.php" style="margin-left: 12px"><span>Home</span></a></li>
<li><a href="madmin.php?nuser=1"><span>NewUsers</span></a></li>
<li><a href="#"><span>Utilities</span></a></li>	
<li><a href="#"><span>Links</span></a></li>	
<li><a href="../include/sessout.php"><span>Logout</span></a></li>	
</ul>
</div>

<div class="ubercolordivider"> </div>

<div>
<td colspan=0 align="right" bgcolor="#FFFFFF"><input name="insert" type="submit" id="insert" value="Authorize"></td>
<!--td align="left" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Reject"></td-->
</div>

</tr>

<?php
if ($_GET['nuser']==1)
{
connecttodb("localhost","drc","root",""); // Why again here??
madmin();
}
?>

<?php
if ($_GET['iuser']==1)
{
connecttodb("localhost","drc","root","");// Why again here??
insuser();
}
?>

</body>
</html>

******************************
/* this function is available in a library file - in the same way want to have for deletion also*/
function insuser()     // instead of function simply check button set or not
{
	global $iusers;
       	if(empty($_POST['checkbox']))
	{
		echo "No record has been checked ....";
		exit;
	}
	else
	{		
		$matchstring = "";
		$ispresent = 0;
		foreach ($_POST['checkbox'] as $v)
		 	{
				$ispresent = 1;
				$ins_id = mysql_real_escape_string($v); 
				$matchstring = $matchstring.","."'".$ins_id."'";
		 	}
		if ($ispresent == 1)
		{
			$matchstring = substr($matchstring,1);
			$sql="update users set authorize=1 where name in (".$matchstring.")";
                        $result=mysql_query($sql) or die ('Authorization failed.'.mysql_error());
			echo "Successfully authorized";
			madmin();
		}
		else
		{
			echo "No Records to Authorize";
		}

	}
}

***********************************
/*this is the way am displaying Users details - with checkboxes */

while ($row = mysql_fetch_array($nusers))
	{
		echo "<tr>";
		echo '<td align="center" bgcolor="FAFAD2"><input name="checkbox['.$i.']" type="checkbox" id="checkbox['.$i.']" value='.$row['name'].' onclick="javascript:checkbox();">'; 
		$i=$i+1;
		echo "<td align=left bgcolor='FAFAD2'>";
		echo $row["name"];
		echo "</td>";
		echo "<td align=center bgcolor='FAFAD2'>";
		echo $row["company"];
		echo "</td>";
		echo "<td align=center bgcolor='FAFAD2'>";
		echo $row["dept"];
		echo "</td>";
		echo "<td align=center bgcolor='FAFAD2'>";
		echo $row["location"];
		echo "</td>";
		echo "</tr>";
	}
	echo "</table>";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.