PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 11th, 2002, 11:08 AM
adrian adrian is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
A couple more php questions

I'm starting to feel a bit embarrased keep asking for help in here but i'll have to go more red faced.

Problem one i'm having is :-

From my html homepage there are links to php pages and the links take the form of "/leaguetables.php?age=10" or similar. I have installed apache server with php 4.1.2 so i can test everything locally under a windows enviroment. When i have register_globals set to on everything works fine but when using ?age=10 or similar in the link and register_globals is off (which is what i want because my final host is set to this) then i get the Couldn't execute query error. the first bit of code that will be giving this error is

<?
REQUIRE ("connect.php");

$table_name = "leaguetables";

$connection = @mysql_connect("$host", "$user", "$pass")
or die("Couldn't connect.");

$db = @mysql_select_db($db_name, $connection)
or die("Couldn't select database.");


$sql = "SELECT id, team, played, won, draw, lost, gf, ga, points, gd, age
FROM $table_name
WHERE age='$age'
ORDER BY points DESC
";

$result = @mysql_query($sql,$connection)
or die("Couldn't execute query.");

?>

After doing an echo $age it appears for some reason it isn't carrying the value across. Could someone please help me with it.

My second problem is that when i'm on say the page which selects league tables for the under 10's, when i click on a link to show the under 12's league tables which is basically the same php page but a different ?age= at the end of the link then it takes me to my home page. If i then click the same link from there it takes me to the correct place. This is a bit irratic as it doesn't do this all the time. It's a similar thing i've had before with entering details with a form. when i clicked submit it would take me to the viewing page without showing the updated data. I got round that by putting in a refresh tag but can't do that in this situation and i really would like to know what's going on and how to sort it.

As usual, thanks for your time and hope someone can help.

Last edited by adrian : October 11th, 2002 at 11:22 AM.

Reply With Quote
  #2  
Old October 11th, 2002, 12:12 PM
beetle18 beetle18 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Victoria, TX
Posts: 29 beetle18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to beetle18 Send a message via AIM to beetle18
Turning register_globals to off means that all the environment variables aren't automatically registered as globals (which is how you are trying to access it.)

Instead, you need to reference that variable via it's respective superglobal array. In this case, $_GET

WHERE age='$_GET[age]'

Note: when accessing the superglobals from outside a string, you need to properly delimit the named index...

$temp = $_GET['age'];


More on superglobals....

Reply With Quote
  #3  
Old October 11th, 2002, 12:43 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
oh, and you should always use addslashes() on strings that goes directly into database queries..
__________________
Best Regards,
Håvard Lindset

Reply With Quote
  #4  
Old October 11th, 2002, 01:17 PM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 50 sec
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
you could declare
PHP Code:
 $_GET['age'] = $age

before the query then use $age inside the query. i think this would be the safest way IMO. Lindset's way works to
__________________




"Only Linux users see the end of crashes."
- Pl4t0

Reply With Quote
  #5  
Old October 11th, 2002, 02:45 PM
adrian adrian is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks folks that's sorted it (easy when you know how

The second problem i've managed to sort myself. it was a probem with my java script menus and not the php.

Once again thanks. I really must get myself a good php/mysql book. maybe then the amount of threads in these forums wouldn't be going up quite as quick.

Reply With Quote
  #6  
Old October 11th, 2002, 07:57 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
oh, just a note, when you call a superglobal array inside a string remember that its an array, and when you call arrays inside a string they should be enclosed in {}

$var = "this is a {$_GET['test']}";

Reply With Quote
  #7  
Old October 11th, 2002, 08:16 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Yup, what Ben said is right.. if you don't enclose the index with single quotation marks ('), like $_GET[somevar], it will trigger a Notice, which will show up if error_reporting is set to E_ALL. Basically, it's because somevar is treated as a constant without being enclosed.

Last edited by Lindset : October 11th, 2002 at 08:18 PM.

Reply With Quote
  #8  
Old October 11th, 2002, 09:50 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Im always right

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > A couple more php questions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT