Forum Moderators: coopster
k, i've built an admin-login page, which upon logging in, displays a list of email addys from our database. You are given the option to add a new one (thru a form, which works perfectly) and 'remove' an entry. This one's where the problem lies. it doesn't show any errors, but it doesn't remove the email, and it jumps to the default page of the page the include file is in.
any help is greatly appreciated.
here it is;
<?php
// NEW EMAIL ADDRESS ENTRY
if ($submit) {
$sql = "INSERT INTO eflyeraddress (Company,
firstName,
lastName,
EMail)
VALUES ('$Company',
'$firstName',
'$lastName',
'$EMail')";
// run SQL against the DB
$result = mysql_query($sql)
or die ("Query failed: ".mysql_error());
echo '<tr><td width="100%" colspan="7" align="left">';
echo '<h2>Record Updated Successfully</h2>';
echo '</td></tr>';
}
if ($delete)
{
// delete a record
$sql = "DELETE FROM eflyeraddress WHERE id='$id'";
$result = mysql_query($sql) or die(mysql_error());
echo '<tr><td width="100%" colspan="7" align="left">';
echo '<h2>Record Deleted</h2>';
echo '</td></tr>';
}
?>
<tr>
<!-- NEW EMAIL ADDRESS FORM -->
<td width="100%" colspan="7" align="left">
<h1> EFlyer Mailing List</h1>
<h2>Insert new Email</h2>
<form action="<?PHP_SELF?>" method="POST">
First Name (if applicable):<br>
<input type="text" name="firstName"><br>
Last Name (if applicable):<br>
<input type="text" name="lastName"><br>
Company:<br>
<input type="text" name="Company"><br>
Email Address:<br>
<input type="text" name="EMail"><br>
<input type="submit" name="submit" value="Submit">
</td>
</tr>
<?php// DISPLAY LIST
$sql = 'SELECT * FROM eflyeraddress ORDER BY EMail';
$result = mysql_query($sql) or die('Error executing query:<br/>'.$sql.'<br/>MySQL said: '.mysql_error());
if (mysql_num_rows($result) < 1)
{
die('<tr><td>There are no listings in the directory. Please try back later.</td></tr></table>');
}
$myrow = array();
$record_count = 1;
$records_per_row = 1;
while ($myrow = mysql_fetch_array($result))
{
$id = $myrow['id'];
$firstName = $myrow['firstName'];
$lastName = $myrow['lastName'];
$Company = $myrow['Company'];
$EMail = $myrow['EMail'];
if ($record_count == 1) {
echo '<tr class="listA">';
echo '<td width="7%"> </td>';
echo '<td width="25%" align="left">' .$EMail. '</td>';
echo '<td width="5%"> </td>';
echo '<td width="25%" align="left">' .$Company. '</td>';
echo '<td width="5%"> </td>';
echo '<td width="25%" align="left"><a href="'.$SERVER['PHP_SELF'].'?id='.$id.'&delete=yes" class="adminnav">remove entry</a></td>';
echo '<td width="7%"> </td>';
echo '</tr>';
}
if ($record_count == 2) {
echo '<tr class="listB">';
echo '<td width="7%"> </td>';
echo '<td width="25%" align="left">' .$EMail. '</td>';
echo '<td width="5%"> </td>';
echo '<td width="25%" align="left">' .$Company. '</td>';
echo '<td width="5%"> </td>';
echo '<td width="25%" align="left"><a href="'.$SERVER['PHP_SELF'].'?id='.$id.'&delete=yes" class="adminnav">remove entry</a></td>';
echo '<td width="7%"> </td>';
echo '</tr>';
$record_count = 0;//reset it
}
$record_count++;//bring it up by one
}
?>
I was going to say it was a register_globals issue, but that would mean your insert would fail too.
Have you tried using the superglobal $_GET?
if ($_GET['delete'])
{
// delete a record
$sql = "DELETE FROM eflyeraddress WHERE id='".$_GET['id']."' LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
echo '<tr><td width="100%" colspan="7" align="left">';
echo '<h2>Record Deleted</h2>';
echo '</td></tr>';
}
dc