Reply
Old 11-03-2009, 08:58 AM Error in syntax
Super Talker

Posts: 109
Name: Not Telling
Trades: 0
This is a pagination script, with a delete function and is in a table. I am getting this error.

Code:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-4,4' at line 1

PHP Code:
<?php
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());
        }
    }
}
  echo 
"<table class=\"gridtable\">
<thead>
    <tr>
        <th align=\"center\" scope=\"col\">Delete?</th>
        <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>
    </tr>
</thead>
<tbody>"
;
echo 
"<form name = 'myform' action='' method='post'>";
$pagenum = (isset($_GET['pagenum'])) ? (int) $_GET['pagenum'] : 1;
$data mysql_query("SELECT * FROM accounts") or die(mysql_error());
$rows mysql_num_rows($data);
$page_rows 4;
$last ceil($rows/$page_rows);
if (
$pagenum 1)
{
$pagenum 1;
}
elseif (
$pagenum $last)
{
$pagenum $last;
}
$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><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>';  
  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 
"</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)
{
}
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> ";
}
?>
What is the problem? And how can I fix it?
__________________
MY MSN: Sith717@Hotmail.com
PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 11-03-2009, 11:29 AM Re: Error in syntax
chrishirst's Avatar
Super Moderator

Posts: 22,245
Location: Blackpool. UK
Trades: 0
"-4,4" is your problem

You need to fix whatever is going wrong with $delete
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-03-2009, 11:49 AM Re: Error in syntax
Super Talker

Posts: 109
Name: Not Telling
Trades: 0
Okay I have updated the code replacing it with this:

Change this line
PHP Code:
$data_p mysql_query("SELECT * FROM accounts $max") or die(mysql_error()); 
to this
PHP Code:
$data_p mysql_query("SELECT * FROM accounts $max") or die("SELECT * FROM accounts $max"); 
It is now showing this error:

Code:
PHP Code:
SELECT FROM accounts limit -4,
This is the updated code.
PHP Code:
<?php
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());
        }
    }
}
  echo 
"<table class=\"gridtable\">
<thead>
    <tr>
        <th align=\"center\" scope=\"col\">Delete?</th>
        <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>
    </tr>
</thead>
<tbody>"
;
echo 
"<form name = 'myform' action='' method='post'>";
$pagenum = (isset($_GET['pagenum'])) ? (int) $_GET['pagenum'] : 1;
$data mysql_query("SELECT * FROM accounts") or die(mysql_error());
$rows mysql_num_rows($data);
$page_rows 4;
$last ceil($rows/$page_rows);
if (
$pagenum 1)
{
$pagenum 1;
}
elseif (
$pagenum $last)
{
$pagenum $last;
}
$max 'limit ' .($pagenum 1) * $page_rows .',' .$page_rows;
$data_p mysql_query("SELECT * FROM accounts $max") or die("SELECT * FROM accounts $max");  
while(
$info mysql_fetch_array$data_p ))
  {
  echo 
"<tr align=\"center\">";
  echo 
'<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$info['id'].'" /></td>';  
  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 
"</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)
{
}
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> ";
}
?>

__________________
MY MSN: Sith717@Hotmail.com
PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
Old 11-03-2009, 04:56 PM Re: Error in syntax
lizciz's Avatar
Ultra Talker

Posts: 330
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Do the same thing for these rows
PHP Code:
$query "DELETE FROM accounts WHERE id = '$delete'";
$result mysql_query($query); 
That is, change into this

PHP Code:
$query "DELETE FROM accounts WHERE id = '$delete'";
$result mysql_query($query) or die($query); 
__________________
596f75206d65616e20796f752063616e2061637475616c6c79 207265616420746869733f
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-03-2009, 06:52 PM Re: Error in syntax
Super Talker

Posts: 109
Name: Not Telling
Trades: 0
Okay I have fixed that. I am now getting this error:


Code:
Notice: Undefined index: pagenum in /home/runehost/public_html/accounts.php on line 330
with this code:

PHP Code:
<?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());
        }
    }
}
  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 4;
$page = (int) $_GET['pagenum'];
$max_pages ceil($rows/$page_rows);
$last ceil($rows/$page_rows);
$pagenum = ($page && $page && $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)
{
}
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> ";
}
?>
what do I do to fix that? also, it shows this
when there are no records in the database:

Picture:


See the:

1 | 2 | Last

Its supposed to hide when there are no records.

Can someone help me out?
__________________
MY MSN: Sith717@Hotmail.com
PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Error in syntax
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.18323 seconds with 13 queries