I've been giving the task to upgrade an old PHP Web app that is written in php 5.2.17 and using Codeigniter. Doing my upgrade from PHP 5.2 to 5.6 I've been running into to some errors. At a first glance it looks like the problems might be a mix of using old PHP syntax as well as some issues with Codeigniter. I have never worked with Codeigniter which is making this task incredible hard.
The problems occurs on a page where you can edit some already existing data on a patient and then submit the new updated data. Pretty much a CRUD.
The crud has been working completely fine on a server supporting > 5.6 PHP, but now that I have transferred to a server that only supports < 5.6 PHP, I've been getting these problems.
First problem: On the form page I get these two errors and the data inside of those variables are not displayed on the page. If I decide to submit the new entered data the new data are not saved as well.
1) Trying to get property of non-object
2) Undefined variable: rows
The page errors lets me know that my error occurs at around these lines:
$anatomic_code = $rows->NerveCode;
$ProxAccess = $rows->ProxAccess;
$DistAccess = $rows->DistAccess;
From reading documentation from Codeigniter I was suggested to use [''] to access the data, if I do the error message "Trying to get property of non-object" goes away, but I still have the second error and still not seeing the data on the page.
Here is a bigger snippet of the code:
<div id="wrapper">
<?
$exam_id = $this->uri->segment(3);
$struct_id = $this->uri->segment(4);
$struct_type = $this->uri->segment(5);
$tech_id = $this->uri->segment(6);
$test_id = $this->uri->segment(7);
$TechName = $query_tech_type->row();
$side = $query_side->row();
//Update form
$hidden = array(
'Exam' => $exam_id,
'Struct_id' => $struct_id,
'Structure_type' => $struct_type,
'Tech_id' => $tech_id,
'Test' => $test_id
);
?>
<img src="<? echo base_url() . "public/holder/back.png"; ?>" border="0" title="Back to test page">
<?
echo form_open("auh/update_enkel_test_values/","", $hidden);
echo "<h2>" . $TechName->Tech_name . "</h2>";
echo "<div id=\"tech_no\" style=\"display:none\">".$tech_id."</div>";
if ($struct_id == "1"){
foreach($query->result() as $rows):
echo "<h3>M." . $rows->MuscleName . ") (" . $side->SideText.")</h3>";
endforeach;
$anatomic_code = $rows->MuscleCode;
}
elseif ($struct_id == "2") {
foreach($query->result() as $rows):
echo "<h3>N." . $rows->NerveName . ") (" . $side->SideText.")</h3>";
endforeach;
$anatomic_code = $rows->NerveCode;
}
elseif ($struct_id == "3") {
foreach($query->result() as $rows):
if ($rows->NerveCode > 10000 ){
echo "<h3>N." . $rows->NerveName . ") (" . $side->SideText.")</h3>";
}
else {
echo "<h3>N." . $rows->NerveName . " (" . $rows->ProxName . " - ";
if ($rows->Code < 3000) {
echo "m.";
}
echo $rows->DistName . ") (" . $side->SideText.")</h3>";
}
endforeach;
$anatomic_code = $rows->NerveCode;
$ProxAccess = $rows->ProxAccess;
$DistAccess = $rows->DistAccess;
}
elseif ($struct_id == "4"){
foreach($query->result() as $rows):
$anatomic_code = $rows->NerveCode;
if ($rows->NerveCode > 10000 ){
echo "<h3>" . $rows->NerveName . " (". $side->SideText .")</h3>";
}
else{
echo "<h3>N." . $rows->NerveName . " - m." . $rows->MuscleName . " (". $side->SideText .")</h3>";
}
endforeach;
}
Look through the backwards incompatible changes in the PHP documentation:
https://secure.php.net/manual/en/migration53.php
https://secure.php.net/manual/en/migration54.php
https://secure.php.net/manual/en/migration55.php
https://secure.php.net/manual/en/migration56.php
Go through each of those and do a find and replace through your codebase. Then you'll be on 5.6. But don't stop there! ;-)
https://secure.php.net/manual/en/migration70.php
https://secure.php.net/manual/en/migration71.php
https://secure.php.net/manual/en/migration72.php
You will find you have less and less things to change with each subsequent upgrade. 5.2 to 5.3 and to 5.4 probably have the most work involved.
You should try and get on version 7.2, the reason being that 5.6 is currently only developing security fixes, and is no longer going to be supported from Jan 1st 2019. Check this link here:
https://secure.php.net/supported-versions.php
Also, you can upgrade your Codeigniter installation. I don't know which version of codeigniter you are using, but you should download the latest version and follow their guide:
https://www.codeigniter.com/userguide3/installation/upgrading.html
Good luck!
Related
I took a part of PHP code from a different Stackoverflow question, and it works perfectly.
<?php header>
//Display IceCast Server Stats
$server = "***********"; //IP (x.x.x.x or domain name)
$iceport = "8070"; //Port
$iceurl = "live"; //Mountpoint
$online = "<font color=green><b>ONLINE</b> </font><br />";
$offline = "<font color=red><b>OFFLINE</b></font><br />";
if($fp = #fsockopen($server, $iceport, $errno, $errstr, '1')) {
fclose($fp);
$ice_status=$online;
echo "<p><b>DJ:</b> $ice_status";
$stats = file("http://" . $server . ":" . $iceport . "/status2.xsl");
$status = explode(",", $stats[5]);
$artist = explode("-", $status[5]);
echo " " . $artist[1];
echo " - ";
echo " " . $artist[2];
echo "<br />";
// echo "<b>Listeners:</b> <b> " . $status[3] . "</b>";
echo "</p>";
//echo "<br />";
//echo "<p><a href=http://" . $server . ":" . $iceport . "/" . $iceurl . " target=new><b>Listen!</b></a></p>";
} else {
$ice_status=$offline;
echo "<p><b>DJ:</b> $ice_status";
}
?>
<hr />
</center>
I'm trying to add the stream name, which is currently:
echo "DJ: $ice_status";
This displays DJ: ONLINE, but I want it to say DJ: (DJ Name/Stream Name)
I do believe its variables from status2.xsl, but I'm a complete noob at this, and can't seem to figure out how to use it. Could anyone tell me what streamname variable would be?
I was also wondering, is it possible to make it so the "nowplaying.php" refreshes, but my whole web page doesn't? I've tried an iframe, but it makes it look really bad, and has errors.
What my website looks like at the moment: https://i.stack.imgur.com/luc4O.jpg
I'd suggest having a look at TheFineManualâ„¢:
http://icecast.org/docs/icecast-2.4.1/server-stats.html#xslt
Especially the part about status-json.xsl. Make sure you are running an up to date version of Icecast. Icecast is available from all major Linux distributions in up to date packaging. Xiph provides independent packaging, which is useful if there are no up to date packages for a distribution, e.g. shortly after an Icecast release.
status2.xsl was an example file, and a bad one at that. It was removed from newer Icecast versions.
I have a small issue, I'm currently trying to display a user's inventory using steam's API, everything that I wanted is done. (it gets the players items, name and displays the skin's image) however it takes a good 9-30seconds for the webpage to load, is it possible to make the loading of the data faster?
<?php
if(!isset($_SESSION["steamid"])): ?>
<a> Log In so you can see your inventory! </a>
<?php else: ?>
<div class="GetInventory">
<?php
$player = file_get_contents("http://steamcommunity.com/profiles/" . $_SESSION["steamid"] . "/inventory/json/730/2");
$player = json_decode($player, true);
foreach($player["rgDescriptions"] as $item) {
$result = #file_get_contents("http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=" . str_replace(" ", "%20", $item["market_hash_name"]));
$result = json_decode($result, true);
if(!empty($result["success"]) && $result["success"] == true && !empty($result["median_price"]))
echo '<img id= "skinimg" src="http://steamcommunity-a.akamaihd.net/economy/image/' . $item["icon_url"] . '"> ' . $item["name"] . " - " . $result["median_price"] . "<br>";}
?>
<?php endif; ?>
This is the code I currently have,does anyone have any sugestion?
http://i.imgur.com/rRP3Ne0.png
I've written a small function (in PHP) to return all AWS instances in my account.
I've tried using the basic describe instances method but it times out (see below).
So the new function uses the getIterator, however, the page still times out. If it set the max results to 10 it works, but I think that defeats the object. I want a full list of all of my instances.
Any thoughts on what I might be doing wrong that would cause my request to time out? The time out message I get is:
Unable to load the webpage because the server sent no data. Error code: ERR_EMPTY_RESPONSE"
public function allInstances(){
$response = $this->ec2Client->getIterator('describeInstances',array(
'Filters' => array(
array(
'Name' => 'instance-state-name',
'Values' => array('running')
)
))
);
return $response;
}
Update to original post:
This is my code for iterating through the results return by the describeInstances itertator. I know I have around 400 instances running, however the result never returns anything more than about 280.
foreach($iterator as $object){
$value = $object['Reservation'];
//echo "<pre>" . print_r($object,true) . "</pre>";
$number = $count++;
echo $count . ">" . "<b>InstanceID: </b>" . $object['InstanceId'] . " <b>AMI: </b>" . $object['ImageId'] . "</br>";
}
So i installed XMAPP to view my php site im developing for a php mysql class at my local college and I ran aground hours ago and have been searching frantically for answers since. whenever i try to view my site all i see is this
" . $row['tid'] . ""; echo $id; $thisName = "\n
" . $row['fname'] . " " . $row['lname'] ."
"; echo $thisName; $description = "\n
" . nl2br($row['description']) . "
"; echo $description; echo ""; } include ("footer.php"); ?>
or something similar. we host on a local server that has everything we need but cannot access it from our homes. I was wondering if anyone could lend me a hand?
It looks like you have an echo statement where you're using a single quote to open a string but not close it. For instance:
echo '" . $row['tid'] . ""; echo $id; $thisName = "
Go search in your source for something like this. I'd bet that this is your error.
I'm sure there is a simple answer to this, but I have been fumbling with everything for almost a week now and surrender. I am trying to build a shopping cart app and every coding solution I build will work when I include the code on the same page, but when I try to use an external page to run the function it does not seem to return the data. I have tried various monitoring techniques to determine what it is happening.
Here is the code for the main page:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Cart Connection</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<p>Will this display?</p>
<p><a href='<?php echo "showCart.php?PHPSESSID=" . session_id() ?>'>View Cart</a></p>
<?php
$Database = "L3TtL2B5DdY";
$Table = "tblProds";
if (isset($_SESSION['curCart']))
$Cart = unserialize($_SESSION['curCart']);
else
{
if (class_exists("shoppingCart"))
{
$Cart = new shoppingCart();
$Cart->setDatabase($Database);
echo ("<p>If statement ran successfully</p>");
}
else
exit("<p>The shoppingCart class is not available!");
}
$Cart->setTable($Table);
$Cart->getProductList();
$_SESSION['curCart'] = serialize($Cart);
?>
<p><a href='<?php echo "showCart.php?PHPSESSID=" . session_id() ?>'>View Cart</a></p>
</body>
</html>
Here is the relevant code on the "shoppingCart.php" page:
<?php
class shoppingCart
{
private $dbConn = "";
private $dbName = "";
private $tableName = "";
private $orders = array();
private $orderTable = array();
function _construct()
{
$this->dbConn = #new mysqli("localhost", "root", "");
if (mysqli_connect_errno())
die("<p>Unable to connect to the database server.</p>" . "<p>Error Code " .
mysqli_connect_errno() . ": " . mysqli_connect_error() . "</p>");
}
public function setDatabase($Database)
{
$this->dbName = $Database;
#$this->dbConn->select_db($this->dbName)
Or die("<p>Unable to select the database.</p>" . "<p>Error code " . mysqli_errno($this->dbConn) .
": " . mysqli_error($this->dbConn) . "</p>");
}
public function setTable($Table)
{
$this->tableName = $Table;
}
public function getProductList()
{
$sqlString = "SELECT prodID, prodName, prodPrice FROM $this->tableName";
#$qryResult = $this->dbConn->query($sqlString)
Or die("<p>Unable to perform the query.</p>" . "<p>Error code " . mysqli_errno($this->dbConn) .
": " . mysqli_error($this->dbConn) . "</p>");
echo "<table width='100%' border='1'>";
echo "<tr><th>Product ID</th><th>Product Name</th><th>Product Price</th><th>Select Item</th></tr>";
$row = $qryResult->fetch_row();
do
{
echo "<tr><td>{$row[0]}</td>";
echo "<td>{$row[1]}</td>";
echo "<td>{$row[2]}</td>";
echo "<td><a href='showCart.php?PHPSESSID=" . session_id() . "&operation=addItem&productID=" . $row[0] .
"'>Add</a></td></tr>";
$row = $qryResult->fetch_row();
} while ($row);
echo "</table>";
}
......
?>
When I try to load the main page it will display the two lines and that is all. I debugged all the errors when I first created the code and thought it would work. When I wrote the original version of this page I put the "connection" code on the same page and the table displayed fine, so I don't know what else it could be.
I installed WAMP on my Windows XP box and it seems to work fine. I haven't touched the configuration files for any of the programs and all my other test code seems to work fine. It is just when I try to contact an external file.
Any help would be greatly appreciated as I think my brain is turning to mush.
Thanks
You probably need to include the ShoppingCart.php file in your main page, so it has the definition of the ShoppingCart class. Try putting at the top of your main page:
<?php require('ShoppingCart.php'); ?>
What I think might be happening is that the cart object is getting unserialised from the Session, but there is no class definition, so it becomes an instance of an incomplete class. When you then call a method on it you are getting a fatal error. What probably doesn't help is that you may not be displaying errors, so the script will just end. You could also try putting at the top of the main page:
<?php ini_set('display_errors', true); ?>
This should make PHP errors get shown.
Edit
It might be worth pointing out that you can't store a database connection in the session. You need to connect to the server / select the database etc. on every request. I don't think your script is currently doing that.
Also, you can store objects in the session without worrying about the serialisation yourself, here is a quick example:
<?php
//include class definition before starting session.
require('ShoppingCart.php');
session_start();
if (!isset($session['cart'])) {
$session['cart'] = new ShoppingCart();
}
$cart = $session['cart'];
//do stuff to cart
$cart->doSomething();
//changes are now saved back to the session when the script is terminated, without you having to do anything.
You need to
include_once("ShoppingCart.php");
Read up on the different ways to include files
http://www.w3schools.com/PHP/php_includes.asp