2

I've been working on some code and tested it on localhost, everything works fine, but when i upload it to my server it doesn't work beyond my php tags. No errors are showing either. I have checked both php versions and on localhost i run version 5.4.7 and on server it's version 5.3.21. Maybe this is causing the problem? Is there something I should look for in the phpinfo()? Am I missing something in my code? Here is the code:

    <!DOCTYPE html>
    <?php phpinfo(); ?>
    <html>
    <head>

    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <meta charset="utf-8">

    <style>
     body { background:black;}
    .toggle { display:none; }

    p {  
  width:570px;
  text-align:justify;
  color:#686868;
  font-family:Georgia, serif;
      }

    h2 { color:black; } 

    button { background:#686868; 
     border:none;
     font-family:Georgia, serif;
     width:570px;
   }
    </style>
    </head>

    <body>
    <?php 
    include('sql.php');

    $i = 0;

    while($i < count($rows)) {
    echo "
    <div>
        <button class='trigger'>
    <table width='100%'>
    <tr>
        <td width='20%'><img src='http://localhost/app-side/Icons/bar_icon.png' />             
                  </td>
        <td width='80%'><h2>{$rows[$i]['titel']} </h2></td> 
    </tr>
    </table>

</button>
       <div class='toggle'>
     <p>
       {$rows[$i]['info']}
     </p>   
   </div>
    </div>";


    $i++;
    }?>

    </body>
    <script>

    $('.trigger').click(function() { 

    $(this).siblings('.toggle').slideToggle('fast');

    });

   </script>
   </html>

When i run it, it shows a black background (as it's suppose to) but everything beyond my php starting tag gets cut off. I have also tried to force my while loop to loop 10 times and also removed the parts where it's getting data from my database to see if it was a mysql related problem. Which I can conclude it's not.

3 Answers 3

2

The following line is the problem:

<img src='http://localhost/app-side/Icons/bar_icon.png

The image cannot being loaded as localhost refers to the local computer of the client (where the browser runs) not to your server. Usually such urls in websites are considered malicious ;)

A workaround to make it work on both localhost and server would be to use an relative path. This can be relative to your document or relative to the DOCUMENT_ROOT of your server. I've used the second approach as I don't know the location of your php file on server.

Solution with link relative to DOCUMENT_ROOT:

Replace:

<img src='http://localhost/app-side/Icons/bar_icon.png

by

<img src='/app-side/Icons/bar_icon.png
Sign up to request clarification or add additional context in comments.

4 Comments

But even when i change it to the rigth path it still doesn't show anything besides the black background.
Which gives you 'Show page source...' in browser
The problem is, I nevet get to the point where the image is shown. I tried to remove the image part and it still only shows the black background, and when i inspect the page it says the body is empty. So it seems like it cuts off my php for some reason.
I fear, then it's not programming related. Should be moved to superuser.com. (Or asked again there)
0

The only thing that I can assume is that $rows is empty and hence the following code does not get run:

// count($rows) could be equal to 0
while($i < count($rows)) { // this condition becomes false in that case
    echo "
    <div>
        <button class='trigger'>
    <table width='100%'>
    <tr>
        <td width='20%'><img src='http://localhost/app-side/Icons/bar_icon.png' />             
                  </td>
        <td width='80%'><h2>{$rows[$i]['titel']} </h2></td> 
    </tr>
    </table>

</button>
       <div class='toggle'>
     <p>
       {$rows[$i]['info']}
     </p>   
   </div>
    </div>";


    $i++;
    }

UPDATE

Based on your comment, it could then due to something inside sql.php, most probably database connection problem. Try putting error_reporting(E_ALL) at the very top of the page and see if that prints out any error.

1 Comment

I have tested this aswell by changing the loop to run 10 times instead of count($rows) and also placed "hello" in both the button and the <p> instead of the data from my database. Same thing happens, no buttons are shown.
0

Have you checked your sql.php to make sure you've changed it to match your live server (changed from localhost variables) also check your database field names versus your script for typos.

[code] 
{$rows[$i]['titel']} </h2></td>
[\code]

Is it supposed to read : [code]

{$rows[$i]['title']} </h2></td>

[\code]

If your database field name is "title" and You are trying to get data from a field called "titel" than that could cause your error.

I hope that helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.