Forum Moderators: coopster

Message Too Old, No Replies

deleting a record

         

ran_dizolph

2:23 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



hi there.

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>&nbsp;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%">&nbsp;</td>';
echo '<td width="25%" align="left">' .$EMail. '</td>';
echo '<td width="5%">&nbsp;</td>';
echo '<td width="25%" align="left">' .$Company. '</td>';
echo '<td width="5%">&nbsp;</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%">&nbsp;</td>';
echo '</tr>';
}

if ($record_count == 2) {
echo '<tr class="listB">';
echo '<td width="7%">&nbsp;</td>';
echo '<td width="25%" align="left">' .$EMail. '</td>';
echo '<td width="5%">&nbsp;</td>';
echo '<td width="25%" align="left">' .$Company. '</td>';
echo '<td width="5%">&nbsp;</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%">&nbsp;</td>';
echo '</tr>';

$record_count = 0;//reset it
}
$record_count++;//bring it up by one

}
?>

dreamcatcher

6:23 pm on Nov 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

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

ran_dizolph

6:49 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



thanks for the response...however, even with said changes, i'm getting the same problem.

i've tried numerous methods to print a message if it does or doesn't delete the email, again, it just reverts to the default page.

i'm soooooo stuck on this...it's killin' me!

any other thoughts?

directrix

7:36 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



Have you tried echoing $id immediately before the delete statement to verify its contents?

ran_dizolph

8:02 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



hi,

k, i got it working (more or less).

i ended up having to take the INSERT and DELETE lines out of the include, and place them in the actual admin file.

it pretty well does what i need it to do now...just still not sure exactly what the problem was tho.

thanks anyways!