What i have works... i can view the entries and delete the rows but I get this error every time:
mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource

If I then reload the page the deleted entry disappears and all is right with the world again.

If someone know why this is happening i would be eternally grateful. :o

<?php
//************************************
//view entry
//
**************************************

$host="";
// username and password to log onto db server
$username="";
$password="";

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("contact_us_admin")or die("cannot select DB");

////////////////////////////////////////
////// DONOT EDIT BELOW /////////
///////////////////////////////////////
$sql="SELECT * FROM contact_us_db order by tm desc";
$result=mysql_query($sql);

$count=mysql_num_rows($result);
?>

<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">

<table border='1' width='1000' cellspacing='0' cellpadding='0' align=center>
<tr>
<td><font face='Verdana' size='2'><b>#</b></font></td>
<td><font face='Verdana' size='2'><b>Name</b></font></td>
<td><font face='Verdana' size='2'><b>City</b></font></td>
<td><font face='Verdana' size='2'><b>State</b></font></td>
<td><font face='Verdana' size='2'><b>Zip</b></font></td>
<td><font face='Verdana' size='2'><b>Email</b></font></td>
<td><font face='Verdana' size='2'><b>Message</b></font></td>
<td><font face='Verdana' size='2'><b>Date</b></font></td>
</tr>

<?
while($rows=mysql_fetch_array($result))
{$dt=date("m/d/y",$rows['tm']); // formating the date
$dtl=nl2br($rows['dtl']); // this will change the line breaks to html line breaks
?>

<tr>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['entry_id']; ?>"></td>
<td><font face='Verdana' size='2'><? echo $rows[FullName]; ?></font></td>
<td><font face='Verdana' size='2'><? echo $rows[City]; ?></font></td>
<td><font face='Verdana' size='2'><? echo $rows[State]; ?></font></td>
<td><font face='Verdana' size='2'><? echo $rows[Zip]; ?></font></td>
<td><font face='Verdana' size='2'><? echo $rows[Email]; ?></font></td>
<td><font face='Verdana' size='2'><? echo $rows[Message]; ?></font></td>
<td><font face='Verdana' size='2'><? echo $dt; ?></font></td>
</tr>

<?php
}
?>

<tr>
<td colspan="5"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>

</table>
</form>
</td>
</tr>
</table>
<?
// Check if delete button active, start this

if(isset($POST['delete'])) {
if (count($
POST['checkbox']) > 0) {
foreach ($_POST['checkbox'] as $del_id) {
$sql = "DELETE FROM contact_us_db WHERE entry_id=' " . $del_id . " ' ";
$result = mysql_query($sql) or die(mysql_error());
if(mysql_affected_rows($result) > 0) echo 'Selected data rows Deleted';
}
}
}

mysql_close();
?>

    print the $sql and test in phpmyadmin.

    hmm.

    $sql = "DELETE FROM contact_us_db WHERE entry_id=' " . $del_id . " ' ";

    there is a whitespace atrer the entry_id 's apostrofe.

      thanks for the reply but I don't understand it. what do you mean by print $sql?
      I can manually delete entries in phpmyadmin but I want this page to do it instead.

        there is a whitespace atrer the entry_id 's apostrofe.

          so this:
          "DELETE FROM contact_us_db WHERE entry_id=' "
          should be this:
          "DELETE FROM contact_us_db WHERE entry_id='"

          [I tried this and it didn't fix it]

            the error points me to this line:
            if(mysql_affected_rows($result) > 0) echo 'Selected data rows Deleted';

              ok so I think i fixed it...

              FYI
              I guess I didn't need the $variable inside mysql_affected_rows(); as it automatically references the last mysql_query().

              so that error line should read:

              if(mysql_affected_rows() > 0) echo 'Selected data rows Deleted';

                Yep, and this generator has brothers LOL :J

                  care to share 🙂?
                  My next project is going up in scale (i want to show info from a db and allow visitors to rate content with stars (they'll be rating submitted user "stories" which consist of videos, photos and text)

                    Write a Reply...