SQL PROBLEM!!

Problems with the Windows version of XAMPP, questions, comments, and anything related.

SQL PROBLEM!!

Postby squills » 24. November 2009 03:58

When i run my page i get this error

SQL Error
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 '' at line 1
in C:\xampp\htdocs\RTN\comment.php, line 21


here is the code for line 21 (first line in code is 21)

Code: Select all
      $ras = mysql_query("SELECT commentpm FROM users WHERE id = $arr[owner]") or sqlerr(__FILE__,__LINE__);
    $arg = mysql_fetch_array($ras);

      $arr = mysql_fetch_array($res,MYSQL_NUM);
      if (!$arr)
        stderr("Error", "No torrent with ID.");


any idea on why i would get this error?
thanks
squills
squills
 
Posts: 15
Joined: 22. November 2009 14:19

Re: SQL PROBLEM!!

Postby ym_chaitu » 24. November 2009 06:41

have u checked whether this one is working in the sql query browser
Code: Select all
SELECT commentpm FROM users WHERE id = $arr[owner]

also check that if the connection to the server is possible by checking ur user id and password..
also check whether the user id u gave have the permission to run the select query..
--
Chaitanya Babu Yanamadala
www.drvirusindia.co.cc
User avatar
ym_chaitu
 
Posts: 33
Joined: 13. November 2009 08:26
Location: Bangalore,India

Re: SQL PROBLEM!!

Postby polonggo » 24. November 2009 09:32

why don't you try this:

Code: Select all
$ras = mysql_query("SELECT commentpm FROM users WHERE id = " . $arr['owner']) or sqlerr(__FILE__,__LINE__);
    $arg = mysql_fetch_array($ras);
polonggo
 
Posts: 4
Joined: 01. September 2009 09:21

Re: SQL PROBLEM!!

Postby squills » 24. November 2009 14:10

Ok i tried the new line of code and got same error.
yes permission is set
when i run a query i get this error

#1064 - 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 '[owner] LIMIT 0, 30' at line 1


this is the results under the error

SELECT commentpm
FROM users
WHERE id = $arr[owner]
LIMIT 0 , 30
squills
 
Posts: 15
Joined: 22. November 2009 14:19

Re: SQL PROBLEM!!

Postby ym_chaitu » 24. November 2009 14:20

instead of $arr[owner] use the name of the owner.
is it giving any results..
--
Chaitanya Babu Yanamadala
www.drvirusindia.co.cc
User avatar
ym_chaitu
 
Posts: 33
Joined: 13. November 2009 08:26
Location: Bangalore,India

Re: SQL PROBLEM!!

Postby squills » 24. November 2009 14:25

yes, if i put in 6 for the user id of someone it returns 1 valid result..

so it looks like this
SELECT commentpm FROM users WHERE id = 6
squills
 
Posts: 15
Joined: 22. November 2009 14:19

Re: SQL PROBLEM!!

Postby ym_chaitu » 24. November 2009 14:31

please paste the entire comment.php
--
Chaitanya Babu Yanamadala
www.drvirusindia.co.cc
User avatar
ym_chaitu
 
Posts: 33
Joined: 13. November 2009 08:26
Location: Bangalore,India

Re: SQL PROBLEM!!

Postby squills » 24. November 2009 14:45

Ok its not tooo pretty :D but let me tell you this much.. the code was working great , all i was doing is adding a mod...

you will see my comments were i said this was replaced with this.. and another spot were it says this is the code i added... I only changed code with in the first 70 or so lines.. and it was not much :D thanks
squills

Code: Select all
<?php

require_once("include/bittorrent.php");


$action = $_GET["action"];

dbconn(false);


loggedinorreturn();

if ($action == "add")
{
  if ($_SERVER["REQUEST_METHOD"] == "POST")
  {
    $torrentid = 0 + $_POST["tid"];
     if (!is_valid_id($torrentid))
         stderr("Error", "Invalid ID.");

      //$res = mysql_query("SELECT name FROM torrents WHERE id = $torrentid") or sqlerr(__FILE__,__LINE__);
    //************REPLACED ^ WITH THIS CODE*****************************************
     $ras = mysql_query("SELECT commentpm FROM users WHERE id = $arr[owner]") or sqlerr(__FILE__,__LINE__);
                  $arg = mysql_fetch_array($ras);
     //**********************************************************************
      $arr = mysql_fetch_array($res,MYSQL_NUM);
      if (!$arr)
        stderr("Error", "No torrent with ID.");

     $text = trim($_POST["text"]);
     if (!$text)
         stderr("Error", "Comment body cannot be empty!");

     mysql_query("INSERT INTO comments (user, torrent, added, text, ori_text) VALUES (" .
         $CURUSER["id"] . ",$torrentid, '" . get_date_time() . "', " . sqlesc($text) .
          "," . sqlesc($text) . ")");

     $newid = mysql_insert_id();
 
     mysql_query("UPDATE torrents SET comments = comments + 1 WHERE id = $torrentid");
   //****************ADDED THIS CODE******************
   if($arg['commentpm'] == 'yes')
                     {
$added = sqlesc(get_date_time());
$subby = sqlesc("Someone has commented on your torrent");
$notifs = sqlesc("You have received a comment on your torrent [url=details.php?id=$torrentid] " . $arr['name'] . "[/url].");
mysql_query("INSERT INTO messages (sender, receiver, subject, msg, added) VALUES(0, " . $arr['owner'] . ", $subby, $notifs, $added)") or sqlerr(__FILE__, __LINE__);
                      } 
   //*****************************************************
     header("Refresh: 0; url=details.php?id=$torrentid&viewcomm=$newid#comm$newid");
     die;
   }

  $torrentid = 0 + $_GET["tid"];
  if (!is_valid_id($torrentid))
      stderr("Error", "Invalid ID.");

   //$res = mysql_query("SELECT name FROM torrents WHERE id = $torrentid") or sqlerr(__FILE__,__LINE__);
   //************REPLACED ^ WITH THIS CODE*****************************************
     $ras = mysql_query("SELECT commentpm FROM users WHERE id = $arr[owner]") or sqlerr(__FILE__,__LINE__);
                  $arg = mysql_fetch_array($ras);
     //**********************************************************************
  $arr = mysql_fetch_assoc($res);
   if (!$arr)
     stderr("Error", "No torrent with ID.");

   stdhead("Add a comment to \"" . $arr["name"] . "\"");

   print("<h1>Add a comment to \"" . htmlspecialchars($arr["name"]) . "\"</h1>\n");
   print("<p><form method=\"post\" action=\"comment.php?action=add\">\n");
   print("<input type=\"hidden\" name=\"tid\" value=\"$torrentid\"/>\n");
   print("<textarea name=\"text\" rows=\"10\" cols=\"60\"></textarea></p>\n");
   print("<p><input type=\"submit\" class=btn value=\"Do it!\" /></p></form>\n");

   $res = mysql_query("SELECT comments.id, text, comments.added, username, users.id as user, users.avatar FROM comments LEFT JOIN users ON comments.user = users.id WHERE torrent = $torrentid ORDER BY comments.id DESC LIMIT 5");

   $allrows = array();
   while ($row = mysql_fetch_assoc($res))
     $allrows[] = $row;

   if (count($allrows)) {
     print("<h2>Most recent comments, in reverse order</h2>\n");
     commenttable($allrows);
   }

  stdfoot();
   die;
}
elseif ($action == "edit")
{
  $commentid = 0 + $_GET["cid"];
  if (!is_valid_id($commentid))
      stderr("Error", "Invalid ID.");

  $res = mysql_query("SELECT c.*, t.name FROM comments AS c LEFT JOIN torrents AS t ON c.torrent = t.id WHERE c.id=$commentid") or sqlerr(__FILE__,__LINE__);
  $arr = mysql_fetch_assoc($res);
  if (!$arr)
     stderr("Error", "Invalid ID.");

   if ($arr["user"] != $CURUSER["id"] && get_user_class() < UC_MODERATOR)
      stderr("Error", "Permission denied.");

   if ($_SERVER["REQUEST_METHOD"] == "POST")
   {
     $text = $_POST["text"];
    $returnto = $_POST["returnto"];

     if ($text == "")
        stderr("Error", "Comment body cannot be empty!");

     $text = sqlesc($text);

     $editedat = sqlesc(get_date_time());

     mysql_query("UPDATE comments SET text=$text, editedat=$editedat, editedby=$CURUSER[id] WHERE id=$commentid") or sqlerr(__FILE__, __LINE__);

      if ($returnto)
        header("Location: $returnto");
      else
        header("Location: $BASEURL/");      // change later ----------------------
      die;
   }

    stdhead("Edit comment to \"" . $arr["name"] . "\"");

   print("<h1>Edit comment to \"" . htmlspecialchars($arr["name"]) . "\"</h1><p>\n");
   print("<form method=\"post\" action=\"comment.php?action=edit&amp;cid=$commentid\">\n");
   print("<input type=\"hidden\" name=\"returnto\" value=\"" . $_SERVER["HTTP_REFERER"] . "\" />\n");
   print("<input type=\"hidden\" name=\"cid\" value=\"$commentid\" />\n");
   print("<textarea name=\"text\" rows=\"10\" cols=\"60\">" . htmlspecialchars($arr["text"]) . "</textarea></p>\n");
   print("<p><input type=\"submit\" class=btn value=\"Do it!\" /></p></form>\n");

   stdfoot();
   die;
}
elseif ($action == "delete")
{
   if (get_user_class() < UC_MODERATOR)
      stderr("Error", "Permission denied.");

  $commentid = 0 + $_GET["cid"];

  if (!is_valid_id($commentid))
      stderr("Error", "Invalid ID.");

  $sure = $_GET["sure"];

  if (!$sure)
  {
       $referer = $_SERVER["HTTP_REFERER"];
      stderr("Delete comment", "You are about to delete a comment. Click\n" .
         "<a href=?action=delete&cid=$commentid&sure=1" .
         ($referer ? "&returnto=" . urlencode($referer) : "") .
         ">here</a> if you are sure.");
  }


   $res = mysql_query("SELECT torrent FROM comments WHERE id=$commentid")  or sqlerr(__FILE__,__LINE__);
   $arr = mysql_fetch_assoc($res);
   if ($arr)
      $torrentid = $arr["torrent"];

   mysql_query("DELETE FROM comments WHERE id=$commentid") or sqlerr(__FILE__,__LINE__);
   if ($torrentid && mysql_affected_rows() > 0)
      mysql_query("UPDATE torrents SET comments = comments - 1 WHERE id = $torrentid");

   $returnto = $_GET["returnto"];

   if ($returnto)
     header("Location: $returnto");
   else
     header("Location: $BASEURL/");      // change later ----------------------
   die;
}
elseif ($action == "vieworiginal")
{
   if (get_user_class() < UC_MODERATOR)
      stderr("Error", "Permission denied.");

  $commentid = 0 + $_GET["cid"];

  if (!is_valid_id($commentid))
      stderr("Error", "Invalid ID.");

  $res = mysql_query("SELECT c.*, t.name FROM comments AS c LEFT JOIN torrents AS t ON c.torrent = t.id WHERE c.id=$commentid") or sqlerr(__FILE__,__LINE__);
  $arr = mysql_fetch_assoc($res);
  if (!$arr)
     stderr("Error", "Invalid ID $commentid.");

  stdhead("Original comment");
  print("<h1>Original contents of comment #$commentid</h1><p>\n");
   print("<table width=500 border=1 cellspacing=0 cellpadding=5>");
  print("<tr><td class=comment>\n");
   echo htmlspecialchars($arr["ori_text"]);
  print("</td></tr></table>\n");

  $returnto = $_SERVER["HTTP_REFERER"];

//   $returnto = "details.php?id=$torrentid&amp;viewcomm=$commentid#$commentid";

   if ($returnto)
       print("<p><font size=small>(<a href=$returnto>back</a>)</font></p>\n");

   stdfoot();
   die;
}
else
   stderr("Error", "Unknown action");

die;
?>
squills
 
Posts: 15
Joined: 22. November 2009 14:19

Re: SQL PROBLEM!!

Postby squills » 25. November 2009 04:22

Any other suggestions?
I assume it has something to do with $arr[owner] Not sure how that is equal to the owner #?
squills
squills
 
Posts: 15
Joined: 22. November 2009 14:19


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 44 guests