DarkJamie Posted February 13, 2010 Share Posted February 13, 2010 I'm hoping there is a simple solution for this problem. Yesterday I upgraded from PHP4 to PHP 5, as I want to use ImageMagick for my photo gallery. Now that I've upgraded, my blog queries only partially work. The following are two snippets of code querying the same db. This is my list page. It displays a list of titles with entry dates. This page works perfectly, and displays everything correctly. <?php //Generate the query $query = "SELECT id, title, content, author, UNIX_TIMESTAMP(entry_date) as date FROM news ORDER BY date DESC LIMIT 3"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // get resultset as object if (mysql_num_rows($result) > 0) { while($send = mysql_fetch_object($result)) { // print details echo "<a href='r.php?id=$send->id'><b class='style2'>$send->title</b></a> "; ?> <font class="style3"> <?php echo date("g:i A - F j, Y", $send->date +7200); ?> </font><br> <?php echo "<font class='style7'><i>Written by: </i><b>$send->author</b> </font><br>"; echo "<br>"; echo nl2br($send->content); echo "<br><br>"; } } ?> This is my results page. When executed, this page returns no result and no error messages. <?php include("includes/dark_db_access.php"); db_login(); //Generate the query to display news content $query = "SELECT title, content, author, UNIX_TIMESTAMP(entry_date) as date FROM news WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // get resultset as object $send = mysql_fetch_object($result); // print details if($send) { echo "<b class='style2'>$send->title</b> "; ?> <font class="style3"> <?php echo date("g:i A - F j, Y", $send->date +7200); ?> </font> <?php echo "<br><i>Written by: </i><b>$send->author</b> "; echo "<br><br>"; echo nl2br($send->content); echo "<br><br><font size=2 color=red><a href=my_sent.php>Main menu.</a></font>"; } ?> Since both queries are written in the same syntax, and the php code to display them is the same, I can not figure out why the results page (by id) fails to display anything. Unfortunately, since I'm hosted with GoDaddy, their geniuses, in their infinite wisdom, thought it best that economy users not have access to error logs, so I can't check them. Altho my brain's logic keeps telling me that if the list page works, and the results page is written the same way, it should work too. Mind you, until I switched to php5 yesterday, all of my db queries were working perfectly. Any ideas would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/191981-mysql-query-by-id-error-upgraded-from-php4-to-php5/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2010 Share Posted February 13, 2010 Where in your second piece of code are you setting the $id variable to a value? Quote Link to comment https://forums.phpfreaks.com/topic/191981-mysql-query-by-id-error-upgraded-from-php4-to-php5/#findComment-1011890 Share on other sites More sharing options...
DarkJamie Posted February 13, 2010 Author Share Posted February 13, 2010 I see where you're going with that, but before the version change, I didn't need to set the $id value for it to work. I'm still trying to wrap my brain around that logic, but it worked fine. I was able to add entries, edit them, delete them, and list them in any fashion i wanted with just the code I had. Now I'm sure the version change shouldn't have made a difference, since nothing on my site is actually dependent on either version yet, but once I implemented the change, the add_entry, edit_entry, delete_entry and results by id all stopped working. Having given thought to this logic, I went back and switched BACK to php4 and everything is working again, so I guess my question should be, with something as simple as a query by ID, how will I need to rework the code to work in php5? Quote Link to comment https://forums.phpfreaks.com/topic/191981-mysql-query-by-id-error-upgraded-from-php4-to-php5/#findComment-1011900 Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2010 Share Posted February 13, 2010 The problem is register_globals and has nothing to do with php5. Register_globals were turned OFF BY DEFAULT in April of the year 2002 (php 4.2) because they allow hackers to set session variables by simply putting GET parameters on the end of URL's when they visit a site. Register_globals being on finally generates a depreciated error in php5.3 and they have been completely removed in php6. You need to correct your code so that it works for all php configurations by using the actual source of the external data. In your case $_GET['id'] Edit: All $_POST, $_GET, $_COOKIE, $_FILES, $_SESSION, $_SERVER, and $_ENV... variables that you code is expecting to be copied into program variables would need to be corrected. If you are using session variables with session_register(), session_is_registered(), or session_unregister() functions, you will need to make addition changes in your code in order to remove those functions. Quote Link to comment https://forums.phpfreaks.com/topic/191981-mysql-query-by-id-error-upgraded-from-php4-to-php5/#findComment-1011902 Share on other sites More sharing options...
DarkJamie Posted February 13, 2010 Author Share Posted February 13, 2010 wow, thank you for that explanation. I'll definitely be reading up on that and making changes as recommended. I'll mark this one solved since this problem requires rewriting my code. Thanks again for your help and quick replies. Quote Link to comment https://forums.phpfreaks.com/topic/191981-mysql-query-by-id-error-upgraded-from-php4-to-php5/#findComment-1011905 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.