Dave2711 Posted July 26, 2009 Share Posted July 26, 2009 Hi, im a bit stuck.. What im trying to do is make a single page for example 'http://www.myexample.com/profile.php", but when it is changed and a number added ie ".com/profile.php?=3" my page will query my database and let me show the data stored for that person. I kinda know what im doing but at the minute im just kinda throwing it together and its not running so smoothly, anyone got any idea where i've gone wrong here? I know that its connected to the database, and the GET ID part is working, but after that im lost <?php include('includes/header.php'); include('includes/configure.php'); $p_id = round($_GET['id']); $result = $database->query("SELECT * FROM img WHERE id=\"$p_id\""); $checkup = $database->fetch($result); ?> ?> <center> <b><?=$checkup['imgcode']?></b> Thanks in advance, Dave. Quote Link to comment https://forums.phpfreaks.com/topic/167499-stuck-using-get-id-to-query-database/ Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 First of all why do you use: $p_id = round($_GET['id']); ? If you want to validate the id value then there are more important checks to be made... Also, you should definitely escape the value before using it in the sql unless the database class does that for you. Try removing the backslashes: $result = $database->query("SELECT * FROM img WHERE id='$p_id'"); You never tell us exactly what is going wrong. Please let us know further. Try avoid using short tags as well. Quote Link to comment https://forums.phpfreaks.com/topic/167499-stuck-using-get-id-to-query-database/#findComment-883237 Share on other sites More sharing options...
mmarif4u Posted July 26, 2009 Share Posted July 26, 2009 Can you be more specific and tells us where you stuck. what errors you get? Quote Link to comment https://forums.phpfreaks.com/topic/167499-stuck-using-get-id-to-query-database/#findComment-883241 Share on other sites More sharing options...
Dave2711 Posted July 26, 2009 Author Share Posted July 26, 2009 Yeh sorry, didnt think to be more specific, i tried what you suggested vineld and there was no change. When I view the page theres no errors it just seems to end after i've included the header, I removed $result = $database->query("SELECT * FROM img WHERE id='$p_id'"); $checkup = $database->fetch($result); And the page works fine, so im assuming i've gone wrong somewhere in these 2 lines.. as it doesnt show my footer or any of the text on the page. Quote Link to comment https://forums.phpfreaks.com/topic/167499-stuck-using-get-id-to-query-database/#findComment-883245 Share on other sites More sharing options...
mmarif4u Posted July 26, 2009 Share Posted July 26, 2009 change this <?=$checkup['imgcode']?> To this: <?php echo $checkup['imgcode']?> Quote Link to comment https://forums.phpfreaks.com/topic/167499-stuck-using-get-id-to-query-database/#findComment-883255 Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 change this <?=$checkup['imgcode']?> To this: <?php echo $checkup['imgcode']?> I already told him to Quote Link to comment https://forums.phpfreaks.com/topic/167499-stuck-using-get-id-to-query-database/#findComment-883259 Share on other sites More sharing options...
Dave2711 Posted July 26, 2009 Author Share Posted July 26, 2009 I wonder if it could possibly be a problem with my mysql connection script? Maybe i've missed something.. I'll rewrite it and see how it goes Quote Link to comment https://forums.phpfreaks.com/topic/167499-stuck-using-get-id-to-query-database/#findComment-883264 Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 Try simply selecting where 1 and see if you can get anything at all out of the database. Quote Link to comment https://forums.phpfreaks.com/topic/167499-stuck-using-get-id-to-query-database/#findComment-883270 Share on other sites More sharing options...
Dave2711 Posted July 26, 2009 Author Share Posted July 26, 2009 Haha, yeh seems the database is responding.. just something ive done has gone wrong, 3 friends of mine who are good at php have had a look and they cant find anything haha, guess PHP just hates me or this free host im using is just lame? Thanks for the help guys, think ill just have to leave it and try another time, lacking patience for it now hehe. Quote Link to comment https://forums.phpfreaks.com/topic/167499-stuck-using-get-id-to-query-database/#findComment-883335 Share on other sites More sharing options...
vineld Posted July 26, 2009 Share Posted July 26, 2009 Print the id and the sql and see if you have the right values. If nothing still seems to be wrong, try using the generated sql directly in for example phpmyadmin and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/167499-stuck-using-get-id-to-query-database/#findComment-883342 Share on other sites More sharing options...
Dave2711 Posted July 26, 2009 Author Share Posted July 26, 2009 I've finally solved it, unfourtunately I dont know what did it but it was something to do with my script connecting me to the database. Thanks for all your help and patience hopefully I can get it all finished now. Thanks again guys, Dave. Quote Link to comment https://forums.phpfreaks.com/topic/167499-stuck-using-get-id-to-query-database/#findComment-883372 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.