Reply
Whats wrong with this? | view.php?ID=$ID
Old 01-05-2009, 06:41 PM Whats wrong with this? | view.php?ID=$ID
pappasaa's Avatar
Extreme Talker

Posts: 240
I am trying to use a page to view data via a link from another page.

I am trying to do it like this:
Code:
<a href="http://www.somewebsite.com/view.php?ID=$ID">CLICK HERE</a>

and depending on the table id you go to my view page ( example URL )
Code:
http://www.somewebsite.com/view.php?ID=2
and i am trying to pull the data fot that table id...can anyone see anything wrong with this. I know all my DB settings are good.

Code:

<?php
include ("include/header.inc.php");

include ("include/dbconnect.php");

if ($ID) {


$result = mysql_query("SELECT * FROM $table WHERE ID=$ID",$db);

   



   $links = mysql_fetch_array($result);
   
        $ID = $links["ID"];
	$paypal = $links["paypal"];
	$contact = $links["contact"];
        $mob_id = $links["mob_id"];
	$mob_name = $links["mob_name"];
   
	echo "<table width=100% border=0><tr><td valign=top width=50%>";
	

echo "<h3>MOBSTER Name: </b>$mob_name</h3><hr>
<b>$mob_name PayPal E-mail:</b> $paypal<br>
<b>$mob_name contact e-mail:</b>$contact<br>
<b>$mob_name MySpace MOBSTER ID: $mob_id<br>
<br><br><a href='edit.php?ID=$ID'>Edit $mob_name Information</a><br>";
	
	echo "</td><td valign=top width=50%></td></tr></table>";
	
	
} else {

	echo "You need to select customer";

	}

include ("include/footer.inc.php");

?>
__________________
Sheep go to heaven....Goats go to hell...
PoliticalJib.com | ArrogantRant.com | BigInfo.org | MyNewsPlus.com |<- Bloggers Wanted
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
When You Register, These Ads Go Away!
Old 01-05-2009, 06:57 PM Re: Whats wrong with this? | view.php?ID=$ID
jason_alan's Avatar
Skilled Talker

Posts: 98
Name: Jason
Location: Seattle, WA
If you don't have register_globals enabled (recommended) then the $ID variable won't be available. Try using $_GET['ID'] instead. Otherwise looks fine
jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 07:15 PM Re: Whats wrong with this? | view.php?ID=$ID
Decaf's Avatar
Ultra Talker

Posts: 490
Name: Adam
Quote:
Originally Posted by jason_alan View Post
If you don't have register_globals enabled (recommended) then the $ID variable won't be available. Try using $_GET['ID'] instead. Otherwise looks fine
Yep, you have to declare that "$ID" gets its value from the URL.
__________________
Decaf is online now
Reply With Quote
View Public Profile Visit Decaf's homepage!
 
Old 01-05-2009, 07:27 PM Re: Whats wrong with this? | view.php?ID=$ID
pappasaa's Avatar
Extreme Talker

Posts: 240
So change this view.php?ID=$ID

to this view.php?ID=$_GET['ID']


or this if ($ID)

to if ($_GET['ID'])


I am still learning
__________________
Sheep go to heaven....Goats go to hell...
PoliticalJib.com | ArrogantRant.com | BigInfo.org | MyNewsPlus.com |<- Bloggers Wanted
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 01-05-2009, 07:32 PM Re: Whats wrong with this? | view.php?ID=$ID
jason_alan's Avatar
Skilled Talker

Posts: 98
Name: Jason
Location: Seattle, WA
Quote:
Originally Posted by pappasaa View Post
So change this view.php?ID=$ID

to this view.php?ID=$_GET['ID']


or this if ($ID)

to if ($_GET['ID'])


I am still learning
Second choice, keep the url to view.php?ID=12345

Remember you should access all url parameters with the $_GET['var'] syntax, and post variables with $_POST['var'] and so on...

Use print_r to debug variables for values when you're stuck, e.g. print_r($_REQUEST)
jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-05-2009, 07:59 PM Re: Whats wrong with this? | view.php?ID=$ID
Decaf's Avatar
Ultra Talker

Posts: 490
Name: Adam
Quote:
Originally Posted by pappasaa View Post
So change this view.php?ID=$ID
to this view.php?ID=$_GET['ID']
or this if ($ID)
to if ($_GET['ID'])
I am still learning
example.com/?id=$_GET['ID'] - Will Not be a valid URL
example.com/?id=12 - Is Valid
* Using the URL From Above *
PHP Code:
$id $_GET['id'];
print 
$id// Prints 12 
Does it make scene now?
__________________
Decaf is online now
Reply With Quote
View Public Profile Visit Decaf's homepage!
 
Old 01-05-2009, 08:23 PM Re: Whats wrong with this? | view.php?ID=$ID
pappasaa's Avatar
Extreme Talker

Posts: 240
i got this and now it loads the page...i.e. all my little titles but its not pulling the data and giving me an error

here is what i got
Code:
<?php
include ("include/header.inc.php");

include ("include/dbconnect.php");


if ($_GET['ID'])  

{

$result = mysql_query("SELECT * FROM $table WHERE ID=$ID",$db);

   



   $links = mysql_fetch_array($result);
   
        $ID = $links["ID"];
	$paypal = $links["paypal"];
	$contact = $links["contact"];
        $mob_id = $links["mob_id"];
	$mob_name = $links["mob_name"];

   
	echo "<table width=100% border=0><tr><td valign=top width=50%>";
	

echo "<h3>MOBSTER Name: </b>$mob_name</h3><hr>
<b>$mob_name PayPal E-mail:</b> $paypal<br>
<b>$mob_name contact e-mail:</b>$contact<br>
<b>$mob_name MySpace MOBSTER ID: $mob_id<br>
<br><br><a href='edit.php?ID=$ID'>Edit $mob_name Information</a><br>";
	
	echo "</td><td valign=top width=50%></td></tr></table>";
	
	
} else {

	echo "You need to select customer";

	}

include ("include/footer.inc.php");

?>

here is the error
Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/biginfoo/public_html/gethitlisted/admin/view.php on line 17
__________________
Sheep go to heaven....Goats go to hell...
PoliticalJib.com | ArrogantRant.com | BigInfo.org | MyNewsPlus.com |<- Bloggers Wanted
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 01-05-2009, 08:36 PM Re: Whats wrong with this? | view.php?ID=$ID
pappasaa's Avatar
Extreme Talker

Posts: 240
i got it

I had to change this
Code:
$result = mysql_query("SELECT * FROM $table WHERE ID=$ID",$db);
to this
Code:
$result = mysql_query("SELECT * FROM $table WHERE ID",$db);
__________________
Sheep go to heaven....Goats go to hell...
PoliticalJib.com | ArrogantRant.com | BigInfo.org | MyNewsPlus.com |<- Bloggers Wanted
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 01-05-2009, 08:37 PM Re: Whats wrong with this? | view.php?ID=$ID
pappasaa's Avatar
Extreme Talker

Posts: 240
thanks for the help
__________________
Sheep go to heaven....Goats go to hell...
PoliticalJib.com | ArrogantRant.com | BigInfo.org | MyNewsPlus.com |<- Bloggers Wanted
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 01-06-2009, 02:39 AM Re: Whats wrong with this? | view.php?ID=$ID
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
I can't see why this works, because you now don't specify what the ID field should equal to.

To prevent errors you have to access arrays in double-quoted strings by using curly brackets:
PHP Code:
$result mysql_query("SELECT * FROM $table WHERE ID={$_GET['ID']}",$db); 
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 01-06-2009, 03:06 AM Re: Whats wrong with this? | view.php?ID=$ID
jason_alan's Avatar
Skilled Talker

Posts: 98
Name: Jason
Location: Seattle, WA
Yeah I have to agree, this won't work right..
Quote:
Code:
$result = mysql_query("SELECT * FROM $table WHERE ID",$db);
I think "this works" is because it is still a valid mysql query.

You need to understand some things about first) sql, then second) php, as the process should go like this:

1) Process posted/url variables with a security check. As in you're expecting a record id which should be a number. So if $_GET['id'] is valid then do a mysql query to get that row.

2) If query returned a row, then display results, otherwise display some kind of error like "No results found". This can be done with:
Code:
if (!$result) {
    print('No Results Found.');
}
3) Also, there are libraries that help with this sort of thing... as in I can construct a sql query and send variables to it without worrying about sql injection, etc... I use pear db. A sample of this is...
Code:
// From url: http://mysite.com/user/?userid=1234
$sql = "SELECT id FROM users WHERE username = ?";
$res = $db->getRow($sql, array($_GET['userid']), DB_FETCHMODE_ASSOC);
// Now $res['username'] = 'username'
4) There are other kinds of php mysql database abstractions you can use as well.., but this one I find easy to use once I have learned it.

Hope that helps!
jason_alan is offline
Reply With Quote
View Public Profile
 
Old 01-06-2009, 11:04 PM Re: Whats wrong with this? | view.php?ID=$ID
pappasaa's Avatar
Extreme Talker

Posts: 240
I did update my code but forgot to post the code here. I am reading the php and sql sites trying to learn the hows and whys so I can do this without help but i keep getting stuck and need to "phone a friend" on some things. I am sorry for not posting an update. I have learned alot from the two threads I have posted so far. I am going to mark this one a solved.

Thank you for getting back to me... your the tips are very useful.
__________________
Sheep go to heaven....Goats go to hell...
PoliticalJib.com | ArrogantRant.com | BigInfo.org | MyNewsPlus.com |<- Bloggers Wanted
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Reply     « Reply to Whats wrong with this? | view.php?ID=$ID
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.13323 seconds with 12 queries