We help IT Professionals succeed at work.

Problems with PHP4 codes in PHP5

remigutten
remigutten asked
on
Medium Priority
557 Views
Last Modified: 2013-12-12
I`m now trying to migrate my codes over from PHP4 to PHP5 (since I`m not able to install PHP4 anymore).
And I can`t really figure out whats new in PHP5, I have read the "PHP: Backward Incompatible Changes" but I really don`t understand that much. I`m not that pro in PHP programming. And I really hope you guys could help me out.

My code below is used to print out some values from a MySQL db to a page. And I`m using AJAX to make the "forms" editable. When I hit the text and edit it, AJAX is sending a request to update the MySQL table. This worked great in PHP4. But now, nothing is stored to the MySQL db.
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.inplace.js"></script>
<?php
##########TILHØRENDE HTML FILER INC/INC-HTML/VIS_ORDRE_FUNC%.php
##########1. FUNKSJON FOR Å OPPDATERER STATUS PÅ ARBEIDSORDREN OM SUBMIT6 ER TRYKKET.
		
			// Dersom submit er trykket oppdaterer vi nyheten.
			if (!empty($_POST["submit6"]))
			{
			
				$query = "UPDATE arbeidsordre 
						SET status='{$_POST['status']}'
						WHERE id = '$_GET[id]'";
					
					// Kjører i gang mysql dersom alt er ok.
					$result = mysql_query($query);
					
					// Skriver ut ok eller feil.
					if($result == 1) {
					echo'Vennligst vent.. <img src="gfx/ajax-loader.gif"><head><META http-equiv="refresh" content="1;URL=index2.php?folder=inc&q=arbeidsrapport&id='.$id.'"></head>';
				} else {
				include("edit/oppdatering_feil.php"); 
						}
			}
			
########## FUNKSJON FOR Å HENTE UT BESKRIVELSE FRA LOGG_RAPPORTER DERSOM DET ER EN.
 
		// Henter verdier fra databasen
		$query = "SELECT *
				FROM kladdelogg 
				WHERE id_ref = '$_GET[id]'";
 
		// Sjekker at sqlen går bra.
		$sql = mysql_query($query);
			if (mysql_num_rows($sql) < 1)	 { echo ''; }
        	while($row = mysql_fetch_array($sql)) {
			
			$id2 = $row['id2'];
			$synlig = $row['synlig'];
			$beskrivelse = $row['beskrivelse'];
		}
			
##########2. FUNKSJON FOR Å VELGE HVILKEN SYLINDER SCRIPTET SKAL HENTE UT. DEFINERES I URL
 
	// Sjekker om brukeren er logget inn
	if(!isset($_SESSION['innlogget'])) { include("404_login.php"); } else {		
		
		// Inkluderer mysql dersom alt er ok.
		include("mysql.php");
		
		// Henter ut riktig sylinder utifra id som er valgt på linken foran fra db.
		$query = "SELECT *, DATE_FORMAT(dato, '%d.%m.%y %H:%i') as 'formatert_dato' 
					FROM arbeidsordre 
					WHERE id=$_GET[id] 
					ORDER BY id 
					DESC LIMIT 1";
					
			// Sjekker at mysql er ok og kjører.
			$sql = mysql_query($query);
				if (mysql_num_rows($sql) < 1)	 { echo 'Ingen arbeidsrapport med dette serienummeret. Prøv igjen'; }
				$teller = 0;
				while($row = mysql_fetch_array($sql)) {
				
				// Skriver ut status og dato rad til bruk.
				$id = $row['id'];
				$dato = $row['formatert_dato'];
				$status = $row['status'];
				$teller++; $color = ($teller % 2) ? '#EEEEEE' : '#FFFFFF';
		
		// Inkluderer knapper og html output med verdier.
		include("inc/knapp_meny.php");
		include("inc/inc-html/vis_ordre_func1.php");
														}
} 
 
?>
</div>
<script type="text/javascript">
        $(document).ready(function(){
                $(".editme1").editInPlace({
                    url: "edit/endre_arbeidsordre.php",
                    params: "ajax=yes"
                });
		
				$(".editme2").editInPlace({
					url: "edit/endre_arbeidsordre.php",
					params: "ajax=yes",
					bg_over: "#cff",
					field_type: "textarea",
					textarea_rows: "7",
					textarea_cols: "70",
					saving_image: "ajax/loading.gif"
				});
				
				$(".editme3").editInPlace({
					url: "edit/endre_arbeidsordre.php",
					params: "ajax=yes",
					field_type: "select",
					select_options: "NEI, JA:0"
				});
				
				$(".editme4").editInPlace({
					url: "edit/endre_arbeidsordre.php",
					params: "ajax=yes",
					field_type: "select",
					select_options: "Ingen, Grieg, Vestfrakt, Nor-Cargo:0"
				});
});
 </script>

Open in new window

Comment
Watch Question

Most Valuable Expert 2011
Author of the Year 2014
Commented:
I can't readily see anything wrong in the code, but here are some things to check.  Run the PHPINFO script on both the PHP4 and PHP5 systems and look at the output line-by-line.  Where you find a difference, post both the PHP4 and PHP5 information here.  I am sure we can help.

The usual things that come up with a conversion like this include reliance on "register_globals" in the PHP4 environment.  That might be an issue, but we won't know till we look at PHPINFO.

Standing by, ~Ray
<?php phpinfo(); ?>

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Afterthought... Try adding this line to the top of the PHP scripts.  It may cause the scripts to throw errors, and you will probably want to take it out after you test, but it will show us where there may be inaccurate assumptions about variable contents.
error_reporting(E_ALL);

Open in new window

Author

Commented:
Thanks Ray Paseur. I jused turned on register_global and EVERYTHING worked again :D THANKS ALOT! :) *happy again*
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Wonderful!  Glad you got it working, and thanks for the points.

But... Some day register_globals is going away.  See the man page here and be aware of the issue so as to avoid trouble in the future.

http://us2.php.net/register_globals

Best regards, ~Ray
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.