Jump to content

What am I doing wrong?


unplugged_web
 Share

Recommended Posts

I wonder if somebody can help me please, I've got this code, but it keeps telling me there's an error telling me that mysql_fetch_array(): supplied argument is not a valid MySQL:

 <?php$con = mysql_connect($host,$username,$password);if (!$con)  {  die('Could not connect: ' . mysql_error());  } mysql_select_db($database, $con);$result = mysql_query("SELECT * FROM portfoliosWHERE artist_id = $idORDER BY order ASC");while($row = mysql_fetch_array($result)){echo $row['name'] . " Portfolio <a href=\"new_site/admin/edit_portfolio.php?artist=$id&portfolio=". $row['id'] . "\" class=\"button\"><img src=\"/new_site/admin/images/edit.png\" title=\"Edit\" /></a> <a href=\"new_site/admin/delete_portfolio.php?artist=$id&portfolio=". $row['id'] . "\" class=\"button\"><img src=\"/new_site/admin/images/delete.png\" title=\"Delete\" /></a> <a href=\"new_site/admin/portfolio_order.php?direction=1&artist=$id&portfolio=". $row['id'] . "\" class=\"button\"><img src=\"/new_site/admin/images/up.png\" title=\"Up\" /></a> <a href=\"new_site/admin/portfolio_order.php?direction=-1&artist=$id&portfolio=". $row['id'] . "\" class=\"button\"><img src=\"/new_site/admin/images/down.png\" title=\"Down\" /></a> <a href=\"new_site/admin/add_to_portfolio.php?artist=$id&portfolio=". $row['id'] . "\" class=\"button\">Add image</a><br />";}mysql_close($con);?>

I've had a look at this page but that gives the impress what I've got is correct

Edited by thehappyappy
Link to comment
Share on other sites

http://w3schools.inv...showtopic=44106 also, this must not be your complete code, because I do not see where you are getting $id from. If so, please provide all relevant code. You do us no favors by omitting out anything that is needed in the debugging assistance of your code. Edited by thescientist
Link to comment
Share on other sites

I tried it without the ORDER BY and it works, as soon as I add that it stops working
I can't change the field name unfortunately, is there another way if do this if that's the problem?
instead of guessing, at least try what's already been suggested to you...
Have you checked mysql_error() to see if it tells you anything?
Edited by thescientist
Link to comment
Share on other sites

ok, cuase you didn't mention that. you only had it checking for the connection, not the actual query.

Edited by thescientist
Link to comment
Share on other sites

IF by removing ORDER as in post #5 there is no error, it can't be connection, therefore MUST be the actual query.
I'm not sure what you're getting at (if your post was directed to me or the OP), but my point was only to get the OP (and others like him/her) to get in the basic habit of debugging their code. Edited by thescientist
Link to comment
Share on other sites

instead of guessing, at least try what's already been suggested to you..
I don't understand why you would imply that the OP, had not tried mysql_error(), how did you know? can you read minds, ah.. well yes then i could understand this reply, but there again as it was already established 5 POST previous, it WAS working but without ORDER, and we identified the problem with a reserved word being used, it seems a pointless statement.
Link to comment
Share on other sites

I don't understand why you would imply that the OP, had not tried mysql_error(), how did you know?
because he said so
I did try checking mysql_error() but it didn't give me any errors at all
however, his code only showed it testing the db connection, as i pointed out in my comment. The point was to test the query as well.
but there again as it was already established 5 POST previous, it WAS working but without ORDER, and we identified the problem with a reserved word being used, it seems a pointless statement.
Which is your opinion, but I am from the school of thought that advising people on how to debug their problems is a good thing. Pointing out multiple ways he could have used mysql_error maybe seem moot to you, but the OP it could have helped him narrow down the issue sooner. If he had mysql_error on the query in the beginning, he would have identified the query as the issue from the outset, as opposed to throwing up a post simply asking "what am i doing wrong?".
Link to comment
Share on other sites

1, "I did try checking mysql_error() but it didn't give me any errors at all" does not tell you he had tried checking the mysql_error(), for connection OR query directly after your comment in post #10, YOU are guessing here. It could have been right after inglome comment at post #2. 2. How do you know where mysql_error() he reported about was not with the query itself, you are guessing again, it is not mentioned at all. 3, Instead of saying "instead of guessing, at least try what's already been suggested to you." Would it not be better to actually point out "Did you use mysql_error on the query? this would have identified the query as the issue from the outset" and then maybe give him an example, instead of implying he was totally ignoring all the suggestions beforehand. And i totally agree about debugging. Instead of guessing, at least try to get all facts before replying.

Link to comment
Share on other sites

:huh:i think JSG said it best once.... "you're weird man" anyway, OP got his problem solved, I was just trying to help out like everyone else. I don't understand why you get so competitive, but if it makes you feel better, then you win.

Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...