Page 1 of 1

processing two submit buttons inside a echo

Posted: Thu Nov 17, 2011 7:40 am
by ljpv14
GUYS I NEED HELP. I use echo to print my form. there is a submit button on the first set of forms. i tried posting it and it works. then i need to have another submit button and used echo again to display that. but there is an error saying: unidentified index delete. I've been trying to fix my code but I can't seem to find what's wrong. HELP GUYS here is the code.

Code: Select all

echo "
<h1>Delete Accounts</h1>
<form action = 'delete.php' =  method= 'post'>
Enter Username:<input type = 'text' name = 'lookup'>
<input type = 'submit' name = 'submit' value='Search'>";

if(isset($_POST['submit']))
{
$x = mysql_query("SELECT * FROM tblaccounts WHERE username = '$_POST[lookup]'");
$row = mysql_fetch_array($x);
	if($row)
	{
		$user = $row['username'];
		$eadd = $row['email'];
		$fname = $row['firstname'];
		$nname = $row['nickname'];
		$lname = $row['lastname'];
		
	echo"
	<table border = 0>
	<tr><td>Username :&nbsp; </td><td>$user<td></tr>
	<tr><td>Password :&nbsp; </td><td>*****<td></tr>
	<tr><td>Email-Address :&nbsp; </td><td>$eadd<td></tr>
	<tr><td>First Name :&nbsp; </td><td>$fname<td></tr>
	<tr><td>Nickname :&nbsp; </td><td>$nname<td></tr>
	<tr><td>Last Name :&nbsp;</td><td>$lname<td></tr>
	</table>";
	echo "<input type = 'submit' name = 'delete' value = 'Delete'></td></tr><br><br>";
	if($_POST['delete'])
	{
		echo "Are you sure you want to delete $user's details?
		<tr><td><input type = 'submit' name = 'yes' value = 'SUBMIT'><input type = 'submit' name = 'no' value = 'No'><br><br></td></tr>
		</form>";
		
		if($_POST['yes'])
		{
			mysql_query("DELETE FROM tblaccounts Where username = '$_POST[lookup]'");
		}
	}
	}

Re: processing two submit buttons inside a echo

Posted: Fri Nov 25, 2011 6:54 am
by Hermit TL
I'm not sure on this but I think the problem lies here:

Code: Select all

$x = mysql_query("SELECT * FROM tblaccounts WHERE username = '$_POST[lookup]'");
and I would replace that with:

Code: Select all

$x = mysql_query("SELECT * FROM tblaccounts WHERE username = '" . $_POST['lookup'] . "'");
and change:

Code: Select all

mysql_query("DELETE FROM tblaccounts Where username = '$_POST[lookup]'");
to

Code: Select all

mysql_query("DELETE FROM tblaccounts Where username = '" . $_POST['lookup'] . "'");
and see if that works.

Also, you may want to be using mysql_real_escape_string() on the $_POST variables before using them in a query.