Using 2 buttons in a form
Moderator: General Moderators
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
Using 2 buttons in a form
I am trying to use 2 buttons in a form and one is edit and other is delete. So they are 2 seperate commands. How does PHP know which one is clicked? Does PHP use the buttons name and then declares the code?
Code: Select all
<?
if ($_GETї'buttonDelete']) {
print "<p>deleted</p>\n";
} else if ($_GETї'buttonEdit']) {
print "<p>edit</p>\n";
}
?>
<form method="get">
<input type="submit" value="Edit" name="buttonEdit">
<input type="submit" value="Delete" name="buttonDelete">
</form>-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
ok, when I click the radio button now after I added that in and everything. This is what shows up in the URL bar for that file.
deledt.php?deledt=14&del=Delete
That is when I hit the Delete button when I select one of the radio buttons. Then I get to the page and it gives me these 2 errors.
deledt.php?deledt=14&del=Delete
That is when I hit the Delete button when I select one of the radio buttons. Then I get to the page and it gives me these 2 errors.
This si the code I have so far... Right now I am just trying to get the delete command working, but it seems to be not working. I think I have the wrong command in to delete the table.Warning: Undefined index: edt in deledt.php on line 43
Warning: Cannot add header information - headers already sent by (output started at header.php:19) in deledt.php on line 50
Code: Select all
<?
require("news_connect.php");
if ($deledt =="") {
header("Location: http://www.bve.32k.org/posts.php");
exit;
}
if ($_GETї'edt']) {
}
else if ($_GETї'del']) {
$sql = "DELETE FROM news_news WHERE id = "$deledt"";
header("Location: http://www.bve.32k.org/posts.php");
exit;
}
?>-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
Action code
Select post code
Code: Select all
<?
require("news_connect.php");
if ($deledt =="") {
header("Location: posts.php");
exit;
}
if ($_GETї'edit']) {
}
else if ($_GETї'submit']) {
$sql = "DELETE FROM news_news WHERE id = "$deledt"";
header("Location: posts.php");
exit;
}
?>Code: Select all
<?
require ("news_connect.php");
$result = mysql_query ('SELECT id,headline,user,timestamp FROM news_news WHERE user="'.$user.'" ORDER BY timestamp');
while ($data = mysql_fetch_array ($result))
{
?>
<form name="deledt" method="get" action="deledt.php">
<table width="425" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td width="20" bgcolor="#B3CDDC"><input type="radio" name="deledt" value="<? echo $dataї"id"]; ?>"></td>
<td width="74" bgcolor="#B3CDDC"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"> <? echo date("m-d-Y", $dataї"timestamp"]) ?></font></td>
<td width="327" bgcolor="#B3CDDC"><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"> <? echo $dataї"headline"]; ?></font></td>
</tr>
</table>
<?
}
?>
<br>
<table width="124" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="124"><div align="center">
<input name="edit" type="submit" class="textbuttons" value="Edit">
<input name="submit" type="submit" class="textbuttons" value="Delete">
</div></td>
</tr>
</table>- AVATAr
- Forum Regular
- Posts: 524
- Joined: Tue Jul 16, 2002 4:19 pm
- Location: Uruguay -- Montevideo
- Contact:
what version of php are you using??? check viewtopic.php?t=511
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Have a try of this for debugging:
When you test for the existance of variables you should be using isset() or empty() - only use this construct:
if you are testing to see whether a variable has a value of TRUE or FALSE.
Mac
Code: Select all
<?php
//trim all the user input to make sure there aren't any stray spaces
foreach ($_GET as $key => $value) {
$_GET[$key] = stripslashes($value);
}
// print_r the array to check the data
echo '<pre>';
print_r($_GET);
echo '</pre>';
require 'news_connect.php';
// use isset() and empty() to test if values are set
// use $_GET['deledt'] instead of $deledt
if (empty($_GET['deledt'])) {
header('Location: posts.php');
exit;
}
if (isset($_GET['edit'])) {
echo 'edit was pressed';
} elseif (isset$_GET['submit']) {
echo 'submit was pressed';
// once again $_GET['deledt'] instead of $deledt
$sql = "DELETE FROM news_news WHERE id = '".$_GET['deledt']"'";
header('Location: posts.php');
exit;
}
?>Code: Select all
if ($variable) {
// blah
} elseif (!$othervariable) {
// blah
}Mac
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan