Jump to content

Issue with database


djfox

Recommended Posts

I get the following errors:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/secrett1/public_html/trances.php on line 23

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

 

 

& instead of loading any part of the file, the whole thing is blank after that.

 

Here`s the coding, can anyone figure out what is wrong with it & know how to fix it:

 

 

$lev=$_SESSION['level2'];

 

$res = mysql_query("SELECT id, name, gallNum, URL, rating, numRates, description, views, cat, addDate, feature, literature FROM image WHERE id=$id");

if ($rows = mysql_fetch_row($res)) {

return $rows;

} else {

print (mysql_error());

}

 

if($submit){

$s = $sub." by ".$name;

$b= emote($bod);

mysql_query("INSERT INTO comment (imageID,subject,content,date,sender) VALUES ( '$id', '$s', '$b', NOW(),$send)")or die ( mysql_error());

mysql_query("INSERT INTO messagedata (recBoxID, sendBoxID, content, subject, isNew, date) VALUES ($rows[2], '7', 'You have a new comment on one of your trances that you have submitted.

Click here to read the comment.

This is automated message please do not reply.', 'New Comment Received', 1, NOW() )");

 

}

if($policy && ($lev>6)){

mysql_query("UPDATE userdata SET violations=SUM(violations,1) WHERE login='$name'");

}

 

$res = mysql_query("SELECT login FROM userdata WHERE id='$rows[2]'");

if ($by = mysql_fetch_row($res)) {

return $by;

} else {

print (mysql_error());

}

 

$res = mysql_query("SELECT icon FROM userdata WHERE id='$rows[2]'");

if ($icon = mysql_fetch_row($res)) {

return $icon;

} else {

print (mysql_error());

}

 

$res = mysql_query("SELECT name, id FROM imagecats WHERE id=$rows[8]");

if ($catName = mysql_fetch_row($res)) {

return $catName;

} else {

print (mysql_error());

}

 

$res = mysql_query("SELECT COUNT(*) FROM comment WHERE imageID='$id'");

if ($numCom = mysql_fetch_row($res)) {

return $numCom;

} else {

print (mysql_error());

}

 

$res = mysql_query("SELECT COUNT(*) FROM userdata WHERE imageFav='%$id%'");

if ($numFavs = mysql_fetch_row($res)) {

return $numFavs;

} else {

print (mysql_error());

}

 

//Update unique pageview counter

if( !$_SESSION["sess_$id"] ){

$_SESSION["sess_$id"] = "visited";

$v = $rows[7] + 1;

mysql_query("UPDATE image SET views=$v WHERE id='$id'");

 

 

Link to comment
Share on other sites

Your queries should look like this:

 

$res = mysql_query(...) or die(mysql_error());

 

Right now you're checking for the error in the wrong place, although it works by luck.

 

As for finding the error, try rewriting your queries again like this, so you can inspect the query you are executing:

 

$sql = "SELECT ...";
$res = mysql_query($sql) or die("Error in $sql\n" . mysql_error());

 

Then you can see the query which failed.  If you can't find the syntax error in the query, post the query here for us to look at.

Link to comment
Share on other sites

Your queries should look like this:

 

$res = mysql_query(...) or die(mysql_error());

 

Right now you're checking for the error in the wrong place, although it works by luck.

 

As for finding the error, try rewriting your queries again like this, so you can inspect the query you are executing:

 

$sql = "SELECT ...";
$res = mysql_query($sql) or die("Error in $sql\n" . mysql_error());

 

Then you can see the query which failed.  If you can't find the syntax error in the query, post the query here for us to look at.

 

Now it says:

Error in SELECT id, name, gallNum, URL, rating, numRates, description, views, cat, addDate, feature, literature FROM image WHERE id= 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

Link to comment
Share on other sites

Change your line from:

$res = mysql_query("SELECT id, name, gallNum, URL, rating, numRates, description, views, cat, addDate, feature, literature FROM image WHERE id=$id");

 

To:

$res = mysql_query("SELECT id, name, gallNum, URL, rating, numRates, description, views, cat, addDate, feature, literature FROM image WHERE id='$id');

Link to comment
Share on other sites

Change your line from:

$res = mysql_query("SELECT id, name, gallNum, URL, rating, numRates, description, views, cat, addDate, feature, literature FROM image WHERE id=$id");

 

To:

$res = mysql_query("SELECT id, name, gallNum, URL, rating, numRates, description, views, cat, addDate, feature, literature FROM image WHERE id='$id');

 

Now the page is completely white with just this error message:

Parse error: syntax error, unexpected T_STRING in /home/secrett1/public_html/trances.php on line 30

 

Line 30 is:

   $s = $sub." by ".$name;

Link to comment
Share on other sites

hmmm, try this real quick instead.

 

$s = $sub;
$s.=" by ";
$s=$name;

 

Oh lorddie, once on thing is changed, another one comes up:

Parse error: syntax error, unexpected T_STRING in /home/secrett1/public_html/trances.php on line 31

 

line 31 is

$s.=" by ";

Link to comment
Share on other sites

Does this work?

 

$s = $sub." "."by"." ".$name;

 

Page still comes back blank, now with this error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/secrett1/public_html/trances.php on line 30

 

Line 30 would be the code you just gave me.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.