multiple Forms and submit buttons

First posting, ran into a problem while coding an assignment.

My page has 2 forms, where the second is created after the user selects edit customer or new customer. At the bottom of the second form is another submit button for adding a new customer into a MySQL table. My problem is when that second form button is pressed it ‘resets’ everything back to showing only one form, and nothing is done. There might be something with the action attribute of my forms but I’ve tried everything I can think of.

heres the php code
[php]
function checkchoice()
{
if (isset($_POST[‘searchcust’]))
{
$searchQuery = “SELECT * FROM CUSTOMERS WHERE First_name= “.”’”.$_POST[“FirstName”]."’".“AND Last_name= “.”’”.$_POST[“LastName”]."’";
editCustomer($searchQuery);
}
else if(isset($_POST[‘newcust’]))
{
echo(“new cust”);
#connect to MySQL database.
$conn = @mysql_connect(“localhost”,“root”,“password”) or die(“Sorry - unable to connect to MySQL!”);

		#make db_mysql the current accessible database
		$db_selected = @mysql_select_db("db_final", $conn);
		if(!$db_selected)
		{
			die("Can't find db_final database in MySQL.".mysql_error());
		}
		#execute the query
		$result=mysql_query("select max(Customer_id) as custid from Customers");
		$row = mysql_fetch_array($result);
		$currentId=$row[custid];
		echo("<br/>Last ID is".$currentId."<br/>");
		echo("Next ID is: ".($currentId +1));
	newCustomer();	
}

}
function newCustomer()
{
echo("






















First Name Last Name Address
Postal-code Phone
Username Password


");
}
function insertCustomer($query)
{
if(!$query.length == 0)
{
#connect to MySQL database.
$conn = @mysql_connect(“localhost”,“root”,“password”) or die(“Sorry - unable to connect to MySQL!”);
	#make db_mysql the current accessible database
	$db_selected = @mysql_select_db("db_final", $conn);
	if(!$db_selected)
	{
		die("Can't find db_final database in MySQL.".mysql_error());
	}
	#execute the query
	$result = mysql_query($query);
}

}
function editCustomer($query)
{
if(!$query.length == 0)
{
#connect to MySQL database.
$conn = @mysql_connect(“localhost”,“root”,“password”) or die(“Sorry - unable to connect to MySQL!”);

	#make db_mysql the current accessible database
	$db_selected = @mysql_select_db("db_final", $conn);
	if(!$db_selected)
	{
		die("Can't find db_final database in MySQL.".mysql_error());
	}
	#execute the query
	$result = mysql_query($query);
	echo("<br/> Search Results <br/>");

	#write the query data to production table
	
	while($row = mysql_fetch_array($result))
	{
		echo("<form name='editcust' id='editcust' method='post'>
		<table cellspacing='0px'>
		<tr>
		<th>First Name</th>
		<th>Last Name</th>
		<th>Address</th></tr>
		<tr><td><input type='text' name='Fname' style='width:200px' value='".$row[1]."'/></td>
		<td><input type='text' name='LName' style='width:200px' value='".$row[2]."'/></td>
		<td><input type='text' name='Address' style='width:200px' value='".$row[3]."'/></td></tr>
		<th>Postal-code</th>
		<th>Phone</th>
		<tr>
		<td><input type='text' name='Post' style='width:200px' value='".$row[4]."'/></td>
		<td><input type='text' name='Phone' style='width:200px' value='".$row[5]."'/></td></tr>
		<th style='border-top-color:black;border-top-width:thin;border-top-style:solid'>Username</th>
		<th style='border-top-color:black;border-top-width:thin;border-top-style:solid'>Password</th>
		<tr><td><input type='text' name='User' style='width:200px' value='".$row[6]."'/></td>
		<td><input type='text' name='Pass' style='width:200px' value='".$row[7]."'/></td>
		</tr>
		<tr>
		<td><input type='submit' name='delete' value='Delete Customer'/></td><td><input type='submit' name='updatecust' value='Update Customer'/></td>
		</tr>
		</table>
		</form>
		");
	}
	mysql_close($conn);
}

}
[/php]

my page starts with just the first form and some submit buttons for retrieving information

<form name="customers" id="customers" method="post">
<table>
<tr><th>Edit</th></tr>
<tr><td>By Full Name: </td><td><input type='text' style='width:200px' name='FirstName'/></td><td><input type='text' style='width:200px' name='LastName'/></td></tr>
<tr><td style=' padding-left:10px'><input type='submit' name='searchcust' value='Get Customer'/></td></tr>
<tr><td style=' padding-left:10px;padding-top:10px'><input type='submit' name='newcust' value='New Customer'/></td></tr>
</table>
</form>
<?php checkChoice()?>

any help would be appreciated, thanks.

<td><input type='submit' name='[b]addnewcust[/b]' value='Add New Customer'/></td>

I don’t see any code to fire this button in you php code.

Sponsor our Newsletter | Privacy Policy | Terms of Service