page work local but not in server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
motiksir
Forum Newbie
Posts: 15
Joined: Sat Oct 22, 2011 5:33 pm

page work local but not in server

Post by motiksir »

i do page in php its work fine in wamp.. but it doesnt work in host..
its display all the images that need but not the table with the info, after the line $row = $res->fetch_array(); its not print nothing

this my code:

Code: Select all

<!DOCTYPE html>
<html>                                                                    
    <head>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
        <link rel="stylesheet" href="menu/menu_style.css" type="text/css" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <style type="text/css">
            body{
                direction: rtl;
                font-family: arial;
                color:black;
            }
            
            #content{
                padding-right:10px;
                margin-top:70px;
                background: #efefef;
                height:500px;
            }
        </style> 
</head>
<body>
<div id="content"> 
<?php
	 if(isset($_REQUEST["id"]))
    {
        $id=$_GET["id"];
        echo($id);
        echo("<br>");
        $strAddress = "Uploaded/";
	// Takes all of the files in the specified folder
	$arrFileNames = scandir($strAddress);          
	$arrLength = count($arrFileNames);
	$nTemp = 0;
	$nCounter = 0;
                    
	if($arrLength > 0)
	{
		echo '<center>';
		echo '<table cellpadding="0" cellspacing="15">';
	}
                    
	foreach($arrFileNames as $strName)
	{
	   
		// Checks if the current element is a name of a picture
		if(($strName!=".") && ($strName!="..") && !strpos($strName, ".txt"))
		{
	        if(strpos($strName,"123321"))
         {
            $arrpic = explode("123321",$strName);
            if($arrpic[0]==$id)
            {
       		// Checks if new line is needed
			if($nTemp == 0)
			{
					echo '<tr>';
			}
			    
			// Creates a new column and puts an image in it
			echo '<td>';
			echo '<img src="'.$strAddress.$strName.'" height="100" width="100" />';
			echo '<br>';

			// Takes only the file name, without the suffix (.jpeg)
			$arrId = explode(".",$strName);

			// Shows the file content to the user
            echo('</td>');                 
			$nTemp++;
                             
			if($nTemp == 3)
			{
			    $nTemp = 0;
			    echo '</tr>';
			}
            }
        }
       
		}
	}
                    
	if($nTemp != 3 || nTemp != 0)
	{
		echo '</tr>';
	}
        
    
    
                        
                   $db = new mysqli("localhost","root","","a");
                    $res = $db->query("SELECT * FROM `carDetails` WHERE `carId` = '".$id."'");
                    $db->query("SET NAMES 'hebrew'");
                    $row = $res->fetch_array();
                    $res->close();
                    $db->close();
                    
                    $toWrite = "<h1><font color=\"red\"><b>".$row["carName"]."</h1></font><table>
                            <tr><td>מחיר:</td><td>".$row["carPrice"]."</td></tr>
                            <tr><td>קילומטרז:</td><td>".$row["carKm"]."</td></tr>
                            <tr><td>שנה:</td><td>".$row["carYear"]."</td></tr>
                            <tr><td>יד:</td><td>".$row["carYad"]."</td></tr>
                            <tr><td>תיבת הילוכים:</td><td>".$row["carBox"]."</td></tr>
                            <tr><td>הערות:</td><td>".$row["carOther"]."</td></tr>
                        </table></b>";
            echo($toWrite);
            
            
            echo("<br/>");
            echo("<br/>");
           
            echo ("<a href=\"stocks.php\">");
            echo ("חזור למלאי רכבים");
            echo("</a>");
    }                     
?>




</div>
</body>
</html>
Last edited by Benjamin on Sat Dec 10, 2011 1:01 pm, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: page work local but not in server

Post by maxx99 »

Is this still valid on your remote server?

Code: Select all

$db = new mysqli("localhost","root","","a");
motiksir
Forum Newbie
Posts: 15
Joined: Sat Oct 22, 2011 5:33 pm

Re: page work local but not in server

Post by motiksir »

in the server all the same without this line
$db = new mysqli("localhost","winpc_auto","autoauto","winpc_auto");
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: page work local but not in server

Post by social_experiment »

Are you receiving any error messages; if it is a problem with the mysqli you should be receiving mysqli related error messages
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
motiksir
Forum Newbie
Posts: 15
Joined: Sat Oct 22, 2011 5:33 pm

Re: page work local but not in server

Post by motiksir »

in the page not appear nothing error.
but the server do a new file error_log and appear this:

[08-Dec-2011 00:41:07] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/winpc/public_html/autoronen/showCar.php:7) in /home/winpc/public_html/autoronen/showCar.php on line 93
[08-Dec-2011 00:41:07] PHP Fatal error: Call to a member function fetch_array() on a non-object in /home/winpc/public_html/autoronen/showCar.php on line 101


line 93: header('Content-Type: text/html; charset=utf-8');
line 101:$row = $res->fetch_array();
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: page work local but not in server

Post by maxx99 »

just vardump($res) or print_r($res) you'll probably see that its empty.
check if your $id isnt empty? if you have a record in db with this id?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: page work local but not in server

Post by social_experiment »

Normally that type of error is indicative of something being called before the header() function;
The Manual wrote:Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
motiksir
Forum Newbie
Posts: 15
Joined: Sat Oct 22, 2011 5:33 pm

Re: page work local but not in server

Post by motiksir »

maxx99 wrote:just vardump($res) or print_r($res) you'll probably see that its empty.
check if your $id isnt empty? if you have a record in db with this id?
i try to do it but not print nothing..
about the $id its not empty.. print it. you can see it in this page..
http://www.kasirgraf.co.il/autoronen/showCar.php?id=5

about the db there a record because in another page i use it in input you can see it here
http://www.kasirgraf.co.il/autoronen/up ... e.php?id=5


social_experiment wrote:Normally that type of error is indicative of something being called before the header() function;
The Manual wrote:Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
i am sorry my friend i am not so much understand what to do... however i delete the line of header and dont have any change
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: page work local but not in server

Post by social_experiment »

The code that you pasted; is it from showCar.php?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
motiksir
Forum Newbie
Posts: 15
Joined: Sat Oct 22, 2011 5:33 pm

Re: page work local but not in server

Post by motiksir »

Yes
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: page work local but not in server

Post by social_experiment »

motiksir wrote:in the page not appear nothing error.
but the server do a new file error_log and appear this:

[08-Dec-2011 00:41:07] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/winpc/public_html/autoronen/showCar.php:7) in /home/winpc/public_html/autoronen/showCar.php on line 93
[08-Dec-2011 00:41:07] PHP Fatal error: Call to a member function fetch_array() on a non-object in /home/winpc/public_html/autoronen/showCar.php on line 101


line 93: header('Content-Type: text/html; charset=utf-8');
line 101:$row = $res->fetch_array();
Output to the browser is already starting at line 7 of this page; possibly the HTML header you have at the top.
motiksir wrote:[08-Dec-2011 00:41:07] PHP Fatal error: Call to a member function fetch_array() on a non-object in /home/winpc/public_html/autoronen/showCar.php on line 101
$row = $res->fetch_array(); where do you define $res as an object prior to this line? You create a new instance using $db so your changes your code like this

Code: Select all

<?php $row = $db->fetch_array(); ?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
motiksir
Forum Newbie
Posts: 15
Joined: Sat Oct 22, 2011 5:33 pm

Re: page work local but not in server

Post by motiksir »

social_experiment wrote:
motiksir wrote:in the page not appear nothing error.
but the server do a new file error_log and appear this:

[08-Dec-2011 00:41:07] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/winpc/public_html/autoronen/showCar.php:7) in /home/winpc/public_html/autoronen/showCar.php on line 93
[08-Dec-2011 00:41:07] PHP Fatal error: Call to a member function fetch_array() on a non-object in /home/winpc/public_html/autoronen/showCar.php on line 101


line 93: header('Content-Type: text/html; charset=utf-8');
line 101:$row = $res->fetch_array();
Output to the browser is already starting at line 7 of this page; possibly the HTML header you have at the top.
motiksir wrote:[08-Dec-2011 00:41:07] PHP Fatal error: Call to a member function fetch_array() on a non-object in /home/winpc/public_html/autoronen/showCar.php on line 101
$row = $res->fetch_array(); where do you define $res as an object prior to this line? You create a new instance using $db so your changes your code like this

Code: Select all

<?php $row = $db->fetch_array(); ?>
this way not solve the problem, however i change the sql
$res = $db->query("SELECT `carId`, `carName`, `carPrice`, `carKm`, `carYear`, `carYad`, `carBox`, `carOther` FROM `cardetails` WHERE `carId` =".$id);

and now it work.. i dont understand why..
but thanks
Post Reply