PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
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 : </td><td>$user<td></tr>
<tr><td>Password : </td><td>*****<td></tr>
<tr><td>Email-Address : </td><td>$eadd<td></tr>
<tr><td>First Name : </td><td>$fname<td></tr>
<tr><td>Nickname : </td><td>$nname<td></tr>
<tr><td>Last Name : </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]'");
}
}
}
Last edited by Benjamin on Thu Nov 17, 2011 9:54 am, edited 1 time in total.
Reason:Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
Notice: Undefined index: delete in C:\xampp\htdocs\xampp\mprob1\delete.php on line 36
I don't think there's something wrong with my query. because when i remove my if condition the query works fine Just having some trouble doing the process inside the if($_POST['delete']){} it seems that the code does not recognize the name 'delete' from my forms.
It's a notice, not an error. It's because you're trying to reference an array index -- $_POST['delete'] in this case -- which may not have been set. Check if it's set first and the notice goes away.
Already tried that. The notice is gone but still the process i defined inside my condition does not happen. When I try to echo my $_POST['delete'] there will be also a notice like what I posted.
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>";
}
I'm referring to this part. It's not happening.
Last edited by Benjamin on Thu Nov 17, 2011 9:55 am, edited 1 time in total.
Reason:Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
That if() statement isn't checking if the value exists - it is only checking if the value evaluates to TRUE. You can use the isset() function to check for a variable's existence:
I already did that too. But I there's still no result. When I try to display all buttons at the same time, they all seem to work but when I display the secona button after the pressing the first one, the second button won't work.
So I see that my delete button is not being posted. Because the value that I determine to my delete button is not listed at the $_POST array. What should I do? I really need to make my delete button work?
if(!empty($_POST('submit')){
switch($_POST['submit']{
case 'Delete':
//print out "yes" "no" buttons
break;
case 'submit': //or search
//print out what you need
break;
case 'yes':
//exec query
case 'no':
default:
break;
}
}
That did the trick! I owe you one! Maybe I really need to learn when to use if statements and case statements. I've been fond on using if statements since I started programming in C. Thank you!