An error I really don't get!


#1

hello,
me and a friend are trying to make something that googles for an image with a random word, then generates some random stats on a trumps card for it. Everything works fine until we add in the database part :(
This is the code we have
snip
This error now fixed, thanks everyone, but more errors are upon us (please see down thread)

TIA,
Richard John


#2

You should look into better debugging methods.

Change this and this should give you the error and what the problem is:

  $query = "SELECT * FROM words ORDER BY left(md5(rand()),6) LIMIT 1"
  $result=mysql_query($query) or die("ERROR 001: " . mysql_error()); 
  $row = mysql_fetch_array("$result"); 

[size=99px]Note: The “Error 001:” part is just so if you have more than one query you know which one is giving you problems.[/size]


#3

I added that, and it now hangs when i visit the page
(Waiting forwww.sprinkles.me.uk) in Firefox


#4

get rid of the quotes around the $results variable

[php]
//Not correct
$row = mysql_fetch_array("$result");
//Correct
$row = mysql_fetch_array($result);[/php]

$result (from your query) is a resource id and does not need to be quoted. By quoting it, you are effectively making it a string and no longer a resource id.


#5

Ooopss…My bad. Sorry about that sprinkles. Guess I should have paid more attention to what I was typing. Thanx peg110 for correcting my error!


#6

Wasn’t just you either Ragster… Sprinkles had it too…
Which I think was the cause of the initial problem.


#7

Thanks for pointing that out, but I now have a new error!
Well, not an error, but the script just hangs and doesnt do anything (tried on two different servers)

what’s causing it to do that?


#8

I looked into the website supplied, and if that is correct address then I get nothing. It loads and the script seems to run, but it doesn’t seem to output anything. And if I am not mistaken then that should be correct cause I do not see anywhere in the script you have provided for anything to be outputed to the browser.


#9

nope, it has imagepng($im); at the end :cry:


#10

time for the good old fashioned echo/print. Put it through out your code (afterevery line if you have too) saying what just happened. You need to find out where the problem is. Then we can try to find out what the problem is.


#11

also ensure that you have the GD Libraray installed (and available to you) in the server you are using.


#12

sorry to be a newb, but what do I echo/print?

And gd is installed


#13

Thanks for helping with the original errors, it turned out to be stuck in a loop!

but, as always with computers, you fix one error, and you get a bunch more! :frowning:

If we comment out the headers and the image copy function, then echo $string we see the google image result for cheese, which is a good sign, however, when we try and make it all work, we get these two errors:

<b>Warning</b>: imagecreatefromjpeg(.jpg): failed to open stream: No such file or directory in <b>/home/sprink54/public_html/index.php</b> on line <b>37</b><br /> <br /> <b>Warning</b>: imagecopy(): supplied argument is not a valid Image resource in <b>/home/sprink54/public_html/index.php</b> on line <b>40</b><br />

(sorry it’s in html, browser shows the page as an image)
I’m guessing this means that it doesnt get the image back from google, but I have no idea why :S

Any ideas greatly appreciated
Richard John