Shipton Posted February 23, 2007 Share Posted February 23, 2007 Alright so I've been going through the PHP/MySQL tutorial on webmonkey (http://www.webmonkey.com/webmonkey/99/21/index3a_page3.html?tw=programming), but no matter what, it doesn't detect an 'id' variable. I've even tried passing variables of other names. It works in the URL, but it never does 'what it's supposed to' - i.e., it just keeps showing the list of names rather than that specific name. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 23, 2007 Share Posted February 23, 2007 Thank you for sharing that with us Recommended reading : http://catb.org/~esr/faqs/smart-questions.html Quote Link to comment Share on other sites More sharing options...
Shipton Posted February 23, 2007 Author Share Posted February 23, 2007 Well my question is, why isn't it working? I can't find any problems, possibly because this is my first time through. Quote Link to comment Share on other sites More sharing options...
Archadian Posted February 23, 2007 Share Posted February 23, 2007 post some of your code so we can see what ur working with. it could be something small Quote Link to comment Share on other sites More sharing options...
Scriptor Posted February 23, 2007 Share Posted February 23, 2007 Posting code helps, we have no idea what 'it' is Quote Link to comment Share on other sites More sharing options...
Shipton Posted February 24, 2007 Author Share Posted February 24, 2007 Actually I did, the URL listed in the first post contains the entire script. Here it is, again: <html> <body> <?php $db = mysql_connect("localhost", "root", "god"); mysql_select_db("mydb",$db); // display individual record if ($id) { $result = mysql_query("SELECT * FROM employees WHERE id=$id",$db); $myrow = mysql_fetch_array($result); printf("First name: %s\n<br>", $myrow["first"]); printf("Last name: %s\n<br>", $myrow["last"]); printf("Address: %s\n<br>", $myrow["address"]); printf("Position: %s\n<br>", $myrow["position"]); } else { // show employee list $result = mysql_query("SELECT * FROM employees",$db); if ($myrow = mysql_fetch_array($result)) { // display list if there are records to display do { printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF, $myrow["id"], $myrow["first"], $myrow["last"]); } while ($myrow = mysql_fetch_array($result)); } else { // no records to display echo "Sorry, no records were found!"; } } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Archadian Posted February 24, 2007 Share Posted February 24, 2007 i don't see where you have anything set to $id you just called the variable, can't do that, what is $id supposed to be? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2007 Share Posted February 24, 2007 You're trying to use register_globals, you need to define $id before using it. $id = $_GET['id']; Quote Link to comment Share on other sites More sharing options...
Barand Posted February 24, 2007 Share Posted February 24, 2007 I expect it's an old tutorial written in the days when "register_globals" was ON by default, in which case a GET or POST variable (eg $_GET['id'] would automatically create the $id variable. Quote Link to comment Share on other sites More sharing options...
Archadian Posted February 24, 2007 Share Posted February 24, 2007 http://www.webmonkey.com/webmonkey/99/21/index3a_page3.html?tw=programming if this is your webaddress going to the script you have provided, there is no id in this URL. This would be $_GET['tw'] and you would have to change "id" in your SELECT statement to your DB you could do http://www.webmonkey.com/webmonkey/99/21/index3a_page3.html?tw=programming&id= but you would have to pass the id through the URL the same way you passed "programming" through Quote Link to comment Share on other sites More sharing options...
Shipton Posted February 24, 2007 Author Share Posted February 24, 2007 You're trying to use register_globals, you need to define $id before using it. $id = $_GET['id']; That got it, thanks very much. Thanks also to everyone who responded! If I have one last question , it would be whether it matters if I use single or double quotes; I see some snippets with either, so I take it it doesn't? Quote Link to comment Share on other sites More sharing options...
Barand Posted February 24, 2007 Share Posted February 24, 2007 There are significant differences in PHP between single and double quoted strings http://www.php.net/manual/en/language.types.string.php Quote Link to comment Share on other sites More sharing options...
Shipton Posted February 24, 2007 Author Share Posted February 24, 2007 That actually clears a lot up, thanks. Alright, yet another newb question spawning from that ancient PHP tutorial: when I do what the guy that wrote it says and give it the extension php3 instead of just php, instead of the expected results, it gives me this: ", $myrow["first"]); printf("Last name: %s\n ", $myrow["last"]); printf("Address: %s\n ", $myrow["address"]); printf("Position: %s\n ", $myrow["position"]); } else { // show employee list $result = mysql_query("SELECT * FROM employees",$db); if ($myrow = mysql_fetch_array($result)) { // display list if there are records to display do { printf("%s %s \n", $PHP_SELF, $myrow["id"], $myrow["first"], $myrow["last"]); } while ($myrow = mysql_fetch_array($result)); } else { // no records to display echo "Sorry, no records were found!"; } } ?> Why is that? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2007 Share Posted February 24, 2007 You probably don't have PHP 3. Everyone's moved up to 4.1 at least, and many hosts are offering 5. If you installed it on your own computer, you should know what version you installed. Quote Link to comment Share on other sites More sharing options...
Shipton Posted February 24, 2007 Author Share Posted February 24, 2007 Ah, I figured it was all-inclusive... I don't do a whole lot of web programming. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.