...

View Full Version : Weird notice after row deletion



bucket
11-04-2009, 12:06 AM
I am getting a weird notice after I delete rows from a database table with php.

This is the error


Notice: Use of undefined constant delchk - assumed 'delchk' in /home/brian/public_html/accounts.php on line 306

Notice: Use of undefined constant delchk - assumed 'delchk' in /home/brian/public_html/accounts.php on line 308




<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

include("inc/config.php");
if (isset($_POST['del']))
{
for ($count = 0;$count<count($_POST[delchk]);$count++)
{
$delete = $_POST[delchk][$count];
$query = "DELETE FROM accounts WHERE id = '$delete'";
$result = mysql_query($query);
if (!$result)
{
die("Error deleting accounts! Query: $query<br />Error: ".mysql_error());
}
}
}
$result = mysql_query("SELECT * FROM accounts");
if(mysql_num_rows($result) > 0)
{

echo "<table class=\"gridtable\">
<thead>
<tr>
<th align=\"center\" scope=\"col\">Username</th>
<th align=\"center\" scope=\"col\">Password</th>
<th align=\"center\" scope=\"col\">Highscores</th>
<th align=\"center\" scope=\"col\">Date</th>
<th align=\"center\" scope=\"col\">IP Address</th>
<th align=\"center\" scope=\"col\">Status</th>
<th align=\"center\" scope=\"col\">Delete?</th>
</tr>
</thead>
<tbody>";
echo "<form name = 'myform' action='' method='post'>";
$data = mysql_query("SELECT * FROM `accounts`") or die(mysql_error());
$rows = mysql_num_rows($data);
$page_rows = 10;
if(!isset($_GET['pagenum']))
{
$page = 1;
}
else
{
$page = (int) $_GET['pagenum'];
}
$max_pages = ceil($rows/$page_rows);
$last = ceil($rows/$page_rows);
$pagenum = ($page && $page > 0 && $page <= $last) ? $page : 1;

$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$data_p = mysql_query("SELECT * FROM accounts $max") or die(mysql_error());
while($info = mysql_fetch_array( $data_p ))
{
echo "<tr align=\"center\">";
echo "<td class=\"valid\" >" . $info['username'] . "</td>";
echo "<td class=\"valid\" >" . $info['password'] . "</td>";
echo "<td><a target=frame2 href='" ."profile/hiscorepersonal.ws?user1=". $info['username'] ."'>Check Highscores</a></td>";
echo "<td>" . $info['addeddate'] . "</td>";
echo "<td>" . $info['ip'] . "</td>";
echo "<td><img src=\"img/invalid.png\" title=\"Account information: INVALID!\"/><img src=\"img/valid.png\" title=\"Account information: VALID!\"/></td>";
echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>';
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "<hr>";
echo "<input type='submit' name = 'del' value='Delete Selected'></form>";
echo "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>";
echo "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>";
echo "<hr>";



if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
echo " | ";
echo " ";
$previous = $pagenum-1;
$current = $pagenum;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>$previous</a> ";
echo " | ";
}
echo "$pagenum";
if ($pagenum == $last || $last == 0)
{
}
else
{
$next = $pagenum+1;
echo " | ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> $next</a> ";
echo " ";
echo " | ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
}
}
else
{
// No rows were found ...
echo '<center>No logged accounts.</center><hr>';
}
?>

What seems to be the problem?

tomws
11-04-2009, 01:55 AM
On those lines, you have:

$_POST[delchk]

That's incorrect (and accidentally functional) array notation. String array keys should be wrapped in single or double quotes.

You don't really bother with annoying things like trouble-shooting before posting a question, do you?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum