ID issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

ID issue

Post by synical21 »

I stayed away from this forum for 2 days! happily working on my php pages and brushing up my html but now im back to bug you again sorry :( Heres my problem:

I have a page which displays applications in a table from my database. Each one of these titles cant be clicked to go to there indervidual page so the full application can be read (example: application.php?ID=1)

That works fine but now i want the page to displayed all the columns for that id row (title,description etc.)

In logic i can do it in my head but putting it down onto php i only got this far (with help of tutorial of course)

Code: Select all

<?php
 
# connect to the database
mysql_connect('localhost','******,'*******');
mysql_select_db('Mini');
 
 
session_start(); 
$my_id = trim (' ' . @$_GET['ID']) ; // will always return a result -- uses '
// sanitize/ clean data value: check for integer value, generate the corresponding string
if ('' < $my_id) { $my_id= (int) $my_id; // extract integer value -- uses '
                           if ( 0 == $my_id) { $my_id= ''; //handle as empty -- uses '
                                                       } else $my_id = "$my_id"; // uses "
                        }
if ('' == $my_id) { //handle the case where no ?ID= present
 
} else { //we have a ID=some integer >0
 
$result = mysql_query("SELECT * FROM fulldata WHERE ID = '$id'")   // This will return one result
or die(mysql_error());  
 
 
}
 
while($row = mysql_fetch_array($result))
{
  echo $row['title'] . " " . $row['descript'];
  echo "<br />";
  }
 
?>
The ID part is a tutorial i learnt so dont know if its completly right but im pretty sure it is. I think the problem lies when i fail attempt to echo the title and descript. I think thats most the info, Thanks for reading.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: ID issue

Post by jackpf »

Right....
Your script looks a bit over complicated tbh...I'm not sure what lines 8-17 are supposed to do....but anyway....

What error are you getting? Or what's not happening that's supposed to be?
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: ID issue

Post by synical21 »

O WOW i fixed it :D :D i read the error and though hmmmm let me try again and BANG it works :D Sorry to waste your time but looks like im learning :)

I had a problem with a variable in the query i made it the column name (id) not the $my_id
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: ID issue

Post by synical21 »

Oh and lines 8-17 are aparently defensive programing 8O
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: ID issue

Post by jackpf »

It looks like a bunch of <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> tbh :P

No offense.

I would suggest that you just run mysql_real_escape_string() on $id and cast it as an (int) (if it should be numeric....which an ID should be).

Also, there's no need for the while() loop if, as the comment suggests, only one row is returned.
Post Reply