Jump to content

Recommended Posts

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  :D

 

<?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.

Link to comment
https://forums.phpfreaks.com/topic/167499-stuck-using-get-id-to-query-database/
Share on other sites

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.

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.

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 :D 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.

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.