LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Apache2 MySQL PHP7 Ubuntu (https://www.linuxquestions.org/questions/linux-software-2/apache2-mysql-php7-ubuntu-4175591904/)

dwmolyneux 10-21-2016 08:24 AM

Apache2 MySQL PHP7 Ubuntu
 
hi I am trying to setup local apache webserver for learning php and mysql but I keep running into an issue of getting blank/white pages where php is used and calling for data from the mysql database.
I goto http://localhost and the index.php page displays as it should...
https://drive.google.com/open?id=0B1...1JEaFpUMEY1WU0 but when I click on the nav links to changes pages the url uses a "index.php?pid=" and then instead of displaying the page as it should it gives a blank/white page....
https://drive.google.com/open?id=0B1...kpPcTBNWmozenc
I have checked the coding and all looks to me like it should and I have done multiple searches to try and find a solution but all I have found is either out-dated or things that are suggested can not be found using the sudo apt or sudo apt-get.
Code:

the files that I can think of that would contain the info https://drive.google.com/open?id=0B1A2ZuAmFkvMZkxLTnQ5eXVQNms was too long to post here and was given invalid when I tried to attach.

Any help would be very much appreciated and thank you a head of time. I'm driving myself insane trying to figure it out. I have been following the tutorials on youtube from "http://www.developephp.com" to give fare credit where do.

agillator 10-21-2016 03:20 PM

What browser are you using? If Firefox, look at the source of the page you go from and to (right click displayed page and select 'View Source'). If not firefox there should be similar functionality somewhere similar. The source code the browser receives should provide at least a hint.

michaelk 10-21-2016 04:19 PM

A blank white page would indicate a php or HTML error. To see the errors look at the /var/log/apache2/error.log. It would help if you post the code (use code tags) or a link to the code.

dwmolyneux 10-22-2016 02:58 AM

here is the most recent log entry from /var/log/apache2/error.log
Code:

[Sat Oct 22 00:53:04.933584 2016] [:error] [pid 1423] [client 127.0.0.1:60912] PHP Notice:  Undefined index: pid in /var/www/html/index.php on line 7
[Sat Oct 22 00:53:13.665797 2016] [:error] [pid 1425] [client 127.0.0.1:60914] PHP Fatal error:  Uncaught Error: Call to undefined function ereg_replace() in /var/www/html/index.php:10\nStack trace:\n#0 {main}\n  thrown in /var/www/html/index.php on line 10, referer: http://localhost/


michaelk 10-22-2016 06:27 AM

There are errors in the index.php code. With out seeing the code there is not much else we can do to help.

dwmolyneux 10-22-2016 06:49 AM

index.php
Code:

<?php
session_start();
/* Created by Adam Khoury @ www.developphp.com */

require_once "scripts/connect_to_mysql.php";
// Determine which page ID to use in our query below ---------------------------------------------------------------------------------------
if (!$_GET['pid']) {
        $pageid = '1';
} else {
        $pageid = ereg_replace("[^0-9]", "", $_GET['pid']); // filter everything but numbers for security
}
// Query the body section for the proper page
$sqlCommand = "SELECT pagebody FROM pages WHERE id='$pageid' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
    $body = $row["pagebody"];
}
mysqli_free_result($query);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Query the module data for display ---------------------------------------------------------------------------------------------------------------
$sqlCommand = "SELECT modulebody FROM modules WHERE showing='1' AND name='footer' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
    $footer = $row["modulebody"];
}
mysqli_free_result($query);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Query the module data for display ---------------------------------------------------------------------------------------------------------------
$sqlCommand = "SELECT modulebody FROM modules WHERE showing='1' AND name='custom1' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
    $custom1 = $row["modulebody"];
}
mysqli_free_result($query);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Build Main Navigation menu and gather page data here -----------------------------------------------------------------------------
$sqlCommand = "SELECT id, linklabel FROM pages WHERE showing='1' ORDER BY id ASC";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());

$menuDisplay = '';
while ($row = mysqli_fetch_array($query)) {
    $pid = $row["id"];
    $linklabel = $row["linklabel"];
       
        $menuDisplay .= '<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br />';
       
}
mysqli_free_result($query);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
//mysqli_close($myConnection);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Website</title>
<style type="text/css">
<!--
body,td,th {
        font-family: Arial Black, Gadget, sans-serif;
        font-size: 12px;
}
body {
        background-image: url(style/stripBG.jpg);
        background-repeat: repeat-x;
        color:#FFF;
        background-color: #996600;
}
a:link {
        color: #FBE7B7;
        text-decoration: none;
}
a:visited {
        text-decoration: none;
        color: #FBE7B7;
}
a:hover {
        text-decoration: underline;
        color: #FFF;
}
a:active {
        text-decoration:none;
        color: #FFF;
}
-->
</style></head>

<body>
<table width="888" border="0" align="center" cellpadding="6">
  <tr>
    <td align="center"><table width="100%" border="0" cellpadding="8">
      <tr>
        <td colspan="2"><table width="100%" border="0">
          <tr>
            <td width="46%"><a href="index.php"><img src="style/logo.png" alt="My Magic Site Logo" width="360" height="80" border="0" /></a></td>
            <td width="54%" valign="top" bgcolor="#150D00"><?php echo $custom1; ?></td>
          </tr>
        </table>
      </td>
        </tr>
      <tr>
        <td width="22%" valign="top" bgcolor="#150D00" style="border:#6B450C thin solid; line-height:1.5em;">
                <?php echo $menuDisplay; ?>
          </td>
        <td width="78%" valign="top" bgcolor="#150D00" style="border:#6B450C thin solid;">
        <div style="width:656px; height:400px; overflow: auto;"><?php echo $body; ?></div>         
        </td>
      </tr>
      <tr>
        <td colspan="2" bgcolor="#150D00" style="border:#6B450C thin solid;"><?php echo $footer; ?>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
        </tr>
    </table>
    &copy;Copyright 2009 Developphp.com</td>
  </tr>
</table>
<div align="center"><a href="administrator">Admin</a></div><br />
</body>
</html>


dwmolyneux 10-22-2016 06:52 AM

Quote:

Originally Posted by dwmolyneux (Post 5620954)
Code:

the files that I can think of that would contain the info https://drive.google.com/open?id=0B1A2ZuAmFkvMZkxLTnQ5eXVQNms was too long to post here and was given invalid when I tried to attach.

file link was posted in my original post.

michaelk 10-22-2016 07:21 AM

The ereg_replace function was removed in php 7

Try:
preg_replace("[^0-9]", "", $_GET['pid'])

dwmolyneux 10-22-2016 07:31 AM

Thank you and that worked. I'll have to look at the other files now and see if any others need to be changed but at least now I know that it was not the problem I was originally thinking it was.

I was starting to beat myself up thinking that I had failed to install something or missed a config somewhere. I'm still fairly new at learning linux.

Turbocapitalist 10-22-2016 08:13 AM

You can use "grep" to look around for other occurrences of the deprecated function.

Code:

grep -n 'ereg_replace' *.php
That will give you line numbers and file names. See the manual page for the full set of options, including PCRE.

One tip you might find useful while working on PHP is to use "tail" to monitor the web log live. Open up an extra terminal window and run it with the -f option:

Code:

tail -f /var/log/apache2/error.log
Then when something fails, just tab to the window to see the notes.


All times are GMT -5. The time now is 01:26 AM.