|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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.... |
|
#3
|
|||
|
|||
|
oh, and you should always use addslashes() on strings that goes directly into database queries..
__________________
Best Regards, Håvard Lindset |
|
#4
|
|||
|
|||
|
you could declare
PHP Code:
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 |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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']}"; |
|
#7
|
|||
|
|||
|
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. |
|
#8
|
|||
|
|||
|
Im always right
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > A couple more php questions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|