homepage Welcome to WebmasterWorld Guest from 54.204.127.191
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Cant find the error.
dkin




msg:3395646
 9:12 am on Jul 16, 2007 (gmt 0)

I am getting this 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 'Resource id #17' at line 1

In this code

$i = 1;

$aresult = mysql_query("SELECT * FROM mmh_pageviews where img = '$file'", $link) or die ("query 1: " . mysql_error());
$num_rows = mysql_num_rows($aresult) or die ("query 1: " . mysql_error());

echo $num_rows;

if ($num_rows == '0')
{
$bresult = mysql_query("SELECT user_id FROM mmh_file_storage where file_name = '$file'", $link) or die ("query 1: " . mysql_error());
$row1 = mysql_query($bresult);

if ($row1['userid']!= 0)
{

$insert = mysql_query("INSERT INTO mmh_pageviews (img, userid, pageviews) VALUES ('$file', '$row1[user_id]', '$i'", $link) or die ("query 1: " . mysql_error());

}
}
else
{
$cresult = mysql_query("SELECT pageviews FROM mmh_pageviews where img = '$file'", $link) or die ("query 1c: " . mysql_error());
$row2 = mysql_query($cresult) or die(mysql_error());

$views = $row2['pageviews'] + $i;

$result = mysql_query("UPDATE mmh_pageviews set pageviews = '$views' where img = '$file'", $link) or die ("query 1d: " . mysql_error());

echo 'Updated';

}

Cant seem to figure out why, this is how I am tracking pageviews, does anyone know a better way?

 

Habtom




msg:3395649
 9:20 am on Jul 16, 2007 (gmt 0)

Which query is the error coming out from?

dkin




msg:3395653
 9:23 am on Jul 16, 2007 (gmt 0)

seems to be coming out directly after echo $num_rows;

Habtom




msg:3395660
 9:36 am on Jul 16, 2007 (gmt 0)

If that is the case, see what comes out of $file by echoing the query.

$aresult = mysql_query("SELECT * FROM mmh_pageviews where img = '$file'", $link) or die ("query 1: " . mysql_error());
$num_rows = mysql_num_rows($aresult) or die ("query 1: " . mysql_error());

echo "SELECT * FROM mmh_pageviews where img = '$file'";

Hab

dkin




msg:3395749
 12:48 pm on Jul 16, 2007 (gmt 0)

hmmmm, Im getting the error because I am trying to query the database but it doesnt exist in it, but thats the thing I need to see if it does exit.

How can I go about doing this a different way?

dkin




msg:3395913
 3:50 pm on Jul 16, 2007 (gmt 0)

anyone?

darrenG




msg:3395928
 3:56 pm on Jul 16, 2007 (gmt 0)

Well at the moment you seem to have a syntax error, so follow habtoms advice and print the query to try to find the error...

dkin




msg:3395944
 4:01 pm on Jul 16, 2007 (gmt 0)

I get an error when I do that query 1:

Thats it.

darrenG




msg:3395955
 4:12 pm on Jul 16, 2007 (gmt 0)

Have you even read habtoms post?

Put the following code above the first query:

echo "SELECT * FROM mmh_pageviews where img = '$file'";

then run the script and copy/paste the query that is output here so we can try find the problem.

dkin




msg:3395986
 4:40 pm on Jul 16, 2007 (gmt 0)

SELECT * FROM mmh_pageviews where img = 'xv82jx9pkuao2shheh6v.jpg'

thats what I get, which is exactly what I want.

sorry been up for 26 hours, misunderstood.

darrenG




msg:3396058
 5:44 pm on Jul 16, 2007 (gmt 0)

Ok sorry, I should have read what you had said properly :)

Anyhow, looking at your code, Id write it something like:

<?php

$q = 'select.....';
$result = mysql_query($q);

if(@ mysql_num_rows($result) == 0) {
//do stuff
} else {
//do other stuff

//etc.

dkin




msg:3396068
 6:06 pm on Jul 16, 2007 (gmt 0)

$q = mysql_query("SELECT * FROM mmh_pageviews where img = 'xv82jx9pkuao2shheh6v.jpg'", $link);
$result = mysql_query($q);

if(@ mysql_num_rows($result) == 0) {
echo 'boo';
} else {
echo 'YAY';
}

thats the code I have now, it should return yay because xv82jx9pkuao2shheh6v.jpg is in the database, not sure why its not.

darrenG




msg:3396151
 7:06 pm on Jul 16, 2007 (gmt 0)

$q = mysql_query("SELECT * FROM mmh_pageviews where img = 'xv82jx9pkuao2shheh6v.jpg'", $link);
$result = mysql_query($q);

Should be

$result = mysql_query("SELECT * FROM mmh_pageviews where img = 'xv82jx9pkuao2shheh6v.jpg'", $link);

Thats my fault, I should have written the code following your conventions :)

dkin




msg:3396160
 7:14 pm on Jul 16, 2007 (gmt 0)

actually noticed that myself after posting, should have edited.

This is the code

$q = mysql_query("SELECT * FROM mmh_pageviews where img = 'xv82jx9pkuao2shheh6v.jpg'", $link);
$result = mysql_query($q);

if(@ mysql_num_rows($result) == 0) {
echo 'boo';
} else {
echo 'YAY';
}

With the same result, boo.

Any Ideas?

Thanks for all the help btw, I really appreciate it.

Dylan

darrenG




msg:3396192
 8:03 pm on Jul 16, 2007 (gmt 0)

$q = "SELECT * FROM mmh_pageviews where img = 'xv82jx9pkuao2shheh6v.jpg'";

$result = mysql_query($q, $link);

if(@ mysql_num_rows($result) == 0) {
echo 'boo';
} else {
echo 'YAY';
}

Try that...

dkin




msg:3396265
 9:28 pm on Jul 16, 2007 (gmt 0)

that part of the script works but for some reason I cant connect to the database like I normally would

$q = "SELECT * FROM mmh_pageviews where img = '$file'";

$result = mysql_query($q, $link);

if(@ mysql_num_rows($result) == 0) {
echo 'boo';
} else {
$row = mysql_query($q, $link);

echo 'a'.$row['pageviews'].'b';

$views = $row['pageviews'] + 1;

$result = mysql_query("UPDATE mmh_pageviews set pageviews = '$views' where img = '$file'", $link);

echo $result;

$row['pageviews'] returns nothing but does have a value in the database.

darrenG




msg:3396288
 9:43 pm on Jul 16, 2007 (gmt 0)

I use a function for connecting and select DB, it saves having to include the DB resource when performing queries.

Anyhow, try this

mysql_connect(connection params);
mysql_select_db('db name');

$q = "SELECT * FROM mmh_pageviews where img = '$file'";

$result = mysql_query($q);

//.....etc

if that doesnt work, Im not really sure what to suggest...

dkin




msg:3396858
 10:25 am on Jul 17, 2007 (gmt 0)

Seeing as php 4 wont be supported anymore, does that mean in order to continue online I need to learn php 5?

Ifs this why my script wont connect?

Still havent gotten it.

The following is my current script, it displays absolutely nothing.

$q = "SELECT * FROM mmh_pageviews where img = '$file'";
$result = mysql_query($q);

if(@ mysql_num_rows($result) == 0) {
$bresult = "SELECT * FROM `mmh_file_storage` WHERE `file_name` = '$file'" or die ("query 1: " . mysql_error());
$row1 = mysql_fetch_array($bresult);

echo $row1['userid'];

if ($row1['userid']!= 0)
{

$insert = mysql_query("INSERT INTO mmh_pageviews (img, userid, pageviews) VALUES ('$file', '$row1[user_id]', '$i'", $link);

Echo 'Worked';
}
} else {

$bresult = "SELECT * FROM mmh_file_storage where file_name = '$file'";
$row = mysql_fetch_array($bresult);

echo $row['file_name'];

$result = mysql_query("UPDATE mmh_pageviews set pageviews = '$views' where img = '$file'");

}

Habtom




msg:3396876
 10:56 am on Jul 17, 2007 (gmt 0)

I have changed a few things, some very important, some not so much, see the changes and implement them.



<?php
$q = "SELECT * FROM mmh_pageviews WHERE img = '". $file ."'";
if(@ mysql_num_rows($q) == 0) {
$bresult = "SELECT * FROM mmh_file_storage WHERE file_name = '". $file ."'" or die ("query 1: " . mysql_error());
while ($row1 = mysql_fetch_array($bresult)) {
if ($row1['userid']!= 0)
{
$insert_data = mysql_query("INSERT INTO mmh_pageviews (img, userid, pageviews) VALUES ('". $file ."', '". $row1[user_id] ."', '". $i ."'");
echo 'Worked';
} else {
$bresult2 = "SELECT * FROM mmh_file_storage WHERE file_name = '$file'";
$row2 = mysql_fetch_array($bresult2);
echo $row2['file_name'];
$result_u = mysql_query("UPDATE mmh_pageviews SET pageviews = '". $views ."' WHERE img = '". $file ."'");
}
}
}
?>

[edited by: Habtom at 10:59 am (utc) on July 17, 2007]

darrenG




msg:3398149
 2:49 pm on Jul 18, 2007 (gmt 0)

Did you resolve the problem?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved