-1

The php code with html below is showing a blank white screen when I open it with a web browser. I have set up a php server to run it. What am I doing wrong?

        <!DOCTYPE html>
        <html>
        <head>
                <title>maro</title>
                <link rel="stylesheet" href="bootstrap.min.css">
                <link rel="stylesheet" href="custom.css">
          </head>
          <body>
                <div class="container-fluid">
                   <form action="imagesear.php" method="get">
                         <div class="row" id="bg">
                         <div class="col-sm-1" id="resdoodle">
                             <a href="index.html"><font color="#FF0000">m</font><font color="#FFA500">a</font><font color="#008000">r</font><font color="#0000FF">o</font></a>
                         </div>
                         <div class="col-sm-6" id="searchbx2">
                             <div class="input-group">
                                 <input type="text" class="form-control" name="search" id="boxstyle2" required>
                                 <span class="input-group-btn">
                                      <input type="submit" class="btn btn-secondary" name="search_btn" value="GO" id="btnstyle2">
                                 </span>
                             </div>
                         </div>
                     </div>
                </form>
            </div>
            <div class="result">    
                <?php
                $search=$_GET["id"];
                $_con=mysqli_connect("localhost","augustus","password");
                mysqli_select_db($_con,"websited");
                $_sql2="select * from webd where stitle like '%$search%'";
                $rs=mysqli_query($_con,$_sql2);
                if(mysqli_num_rows($rs)<1)
                                 {
                                  echo "<center><h4><b>Oops! No result found for your query</b></h4></center>";
                                  exit();
                                 }
                while($resul2=mysqli_fetch_assoc($rs))
                {
                    echo "<a href='".$resul2['slink']."'><img src='".$resul2['simg']."' height='200px' id="imgp"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                }  
                ?>
            </div>
            <script src="jquery.min.js"></script>
            <script src="tether.min.js"></script>
            <script src="bootstrap.min.js"></script>
      </body>
</html>

I tried troubleshooting my php server but it's fine since other php codes are running perfectly. Please help fix this code

Augustoandro
  • 11
  • 1
  • 5
  • 2
    Have you checked your error logs on the server? – Jay Blanchard Jun 10 '19 at 13:59
  • You have a syntax error on line 40 of this code. Use an IDE/Editor with proper syntax highlighting and error checking to better spot these errors. In the meantime, `id="imgp"` needs single quotes. – aynber Jun 10 '19 at 14:07
  • also, possible that fastcgi is not configured properly.plz refer https://www.itsupportwale.com/blog/fixed-nginx-showing-blank-php-pages-with-fastcgi-or-php-fpm/ – dinu0101 Nov 13 '22 at 10:04

2 Answers2

0

For me, it's returning this error:

Parse error: syntax error, unexpected 'imgp' (T_STRING), expecting ',' or ';' in /var/www/html/tmp/test.php on line 38

At this line:

echo "<a href='".$resul2['slink']."'><img src='".$resul2['simg']."' height='200px' id="imgp"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

The id="imgp" is inside double quotes, inside of other string with double quotes. So that's the problem. You need to put single quotes, inside other string with double quotes, to work correctly:

echo "<a href='".$resul2['slink']."'><img src='".$resul2['simg']."' height='200px' id='imgp'></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

Maybe the erros doesn't appear to you, because they are disabled. You can try this, at the begin of php document:

error_reporting(E_ALL);

PS: The errors will appear for the user too, so use with careful.

0

I will give you some recommendations that will help you out and will improve your code.

First: To have errors displayed, as the first thing you should do, above all the rest of your could, in the very first file you load, is to have the errors enabled for purpose of test. You can do some logic in there to not show up if it's production. You have to use these code line:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Second: Try not to mix HTML with PHP. I recommend you to check out Smarty PHP Template. As well as, try to look for How to Implement PHP application with Layer Partner, or PHP Applications with MVC.

Third As I mentioned before, you should not mix HTML with PHP, also, it's better if you use design pattern, that will put your database connection and logic away from the code of the screen. You should have

HTML <= Page.php <=> Database.php

Like this, the Page.php will control what will be shown at the HTML, and will use the functions on Database.php to process database data. The HTML page just outputs the values, it's meant to be just a template.

Blank Pages: Blank page means you have some PHP error and it stopped. Usually showing the errors on the screen will help. This could be a simple type on your code for example.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459