SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Deletejoke PHP script causes Apache to stop working

    Problem: Deletejoke PHP script causes Apache to stop working. All previous scripts in Build Your Own Database Driven Web Site Using PHP & MySQL, Fourth Edition run without a problem. I have verified MySQL tables set-up, and of course, I'm using the appropriate password for my sys. Search in archives and the web for this problem inconclusive. I don't think it's a scripting issue. Apache running locally on my laptop. All "Include" files are where they are supposed to be. Can anybody help me? Thanks in advance!

    Basic computer info:
    Windows Vista Home Premium 2007, w/ Service pack 1
    VAIO Computer, Intel(R) Core(TM)2 Duo CPU T5250 @ 1.50GHz, 1.0 GB RAM, 32-bit OS

    Message from IE version 8.0:
    Internet Explorer cannot display the webpage

    Message from windows pop-up window:
    Apache HTTP Server stopped working and was closed

    error.log:
    [Tue Jul 14 09:28:49 2009] [notice] Parent: child process exited with status 255 -- Restarting.
    httpd.exe: Could not reliably determine the server's fully qualified domain name, using 192.168.1.32 for ServerName
    [Tue Jul 14 09:28:54 2009] [notice] Apache/2.2.11 (Win32) PHP/5.2.10 configured -- resuming normal operations
    [Tue Jul 14 09:28:54 2009] [notice] Server built: Dec 10 2008 00:10:06
    [Tue Jul 14 09:28:54 2009] [notice] Parent: Created child process 5376
    httpd.exe: Could not reliably determine the server's fully qualified domain name, using 192.168.1.32 for ServerName
    httpd.exe: Could not reliably determine the server's fully qualified domain name, using 192.168.1.32 for ServerName
    [Tue Jul 14 09:28:54 2009] [notice] Child 5376: Child process is running
    [Tue Jul 14 09:28:54 2009] [notice] Child 5376: Acquired the start mutex.
    [Tue Jul 14 09:28:54 2009] [notice] Child 5376: Starting 64 worker threads.
    [Tue Jul 14 09:28:54 2009] [notice] Child 5376: Starting thread to listen on port 8080.

    Here is the PHP Script (from Chapter 4, Build Your Own Database Driven Web Site Using PHP & MySQL, Fourth Edition:
    <?php
    if (get_magic_quotes_gpc())
    {
    function stripslashes_deep($value)
    {
    $value = is_array($value) ?
    array_map('stripslashes_deep', $value) :
    stripslashes($value);

    return $value;
    }

    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
    $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
    }

    if (isset($_GET['addjoke']))
    {
    include 'form.html.php';
    exit();
    }

    $link = mysqli_connect('localhost', 'root', 'password');
    if (!$link)
    {
    $error = 'Unable to connect to the database server.';
    include 'error.html.php';
    exit();
    }

    if (!mysqli_set_charset($link, 'utf8'))
    {
    $output = 'Unable to set database connection encoding.';
    include 'output.html.php';
    exit();
    }

    if (!mysqli_select_db($link, 'ijdb'))
    {
    $error = 'Unable to locate the joke database.';
    include 'error.html.php';
    exit();
    }

    if (isset($_POST['joketext']))
    {
    $joketext = mysqli_real_escape_string($link, $_POST['joketext']);
    $sql = 'INSERT INTO joke SET
    joketext="' . $joketext . '",
    jokedate=CURDATE()';
    if (!mysqli_query($link, $sql))
    {
    $error = 'Error adding submitted joke: ' . mysqli_error($link);
    include 'error.html.php';
    exit();
    }

    header('Location: .');
    exit();
    }

    $result = mysqli_query($link, 'SELECT id, joketext FROM joke');
    if (!$result)
    {
    $error = 'Error fetching jokes: ' . mysqli_error($link);
    include 'error.html.php';
    exit();
    }

    while ($row = mysqli_fetch_array($result))
    {
    $jokes[] = array('id' => $row['id'], 'text' => $row['joketext']);
    }

    include 'jokes.html.php';
    ?>
    Last edited by RVSolarGuy; Jul 15, 2009 at 08:59. Reason: Book clarification
    RVSolarGuy

  2. #2
    SitePoint Member
    Join Date
    Dec 2007
    Location
    Utah
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm running into the same problem...at least, it seems the same. I've methodically commented out code until I believe I've identified the lines causing the problem. They are identified in the code sample below in between the comments (lines 87 to 94). Any help will be gratefully appreciated! I'm stuck until I get this one noodled out. All code in the book up to this point works fine.
    PHP Code:
    <?php
    if (get_magic_quotes_gpc())
    {
        function 
    stripslashes_deep($value)
        {
            
    $value is_array($value) ?
                    
    array_map('stripslashes_deep'$value) :
                    
    stripslashes($value);

            return 
    $value;
        }

        
    $_POST array_map('stripslashes_deep'$_POST);
        
    $_GET array_map('stripslashes_deep'$_GET);
        
    $_COOKIE array_map('stripslashes_deep'$_COOKIE);
        
    $_REQUEST array_map('stripslashes_deep'$_REQUEST);
    }

    if (isset(
    $_GET['addjoke']))
    {
        include 
    'form.html.php';
        exit();
    }

    $link mysqli_connect('localhost''root''cushing');
    if (!
    $link)
    {
        
    $error 'Unable to connect to the database server.';
        include 
    'error.html.php';
        exit();
    }

    if (!
    mysqli_set_charset($link'utf8'))
    {
        
    $output 'Unable to set database connection encoding.';
        include 
    'output.html.php';
        exit();
    }

    if (!
    mysqli_select_db($link'ijdb'))
    {
        
    $error 'Unable to locate the joke database.';
        include 
    'error.html.php';
        exit();
    }

    if (isset(
    $_POST['joketext']))
    {
        
    $joketext mysqli_real_escape_string($link$_POST['joketext']);
        
    $sql 'INSERT INTO joke SET
                joketext="' 
    $joketext '",
                jokedate=CURDATE()'
    ;
        if (!
    mysqli_query($link$sql))
        {
            
    $error 'Error adding submitted joke: ' mysqli_error($link);
            include 
    'error.html.php';
            exit();
        }

        
    header('Location: .');
        exit();
    }

    if (isset(
    $_GET['deletejoke']))
    {
        
    $id mysqli_real_escape_string($link$_POST['id']);
        
    $sql "DELETE FROM joke WHERE id='$id'";
        if (!
    mysqli_query($link$sql))
        {
            
    $error 'Error deleting joke: ' mysqli_error($link);
            include 
    'error.html.php';
            exit();
        }

        
    header('Location: .');
        exit();
    }

    $result mysqli_query($link'SELECT id, joketext FROM joke');
    if (!
    $result)
    {
        
    $error 'Error fetching jokes: ' mysqli_error($link);
        include 
    'error.html.php';
        exit();
    }

    // section below seems to cause error

    while ($row mysqli_fetch_array($result))
    {
        
    $jokes[] = array('id' => $row['id'], 'text' => $row['joketext']);
    }

    // section above seems to cause error

    include 'jokes.html.php';
    ?>
    Thanks for any help!

  3. #3
    SitePoint Enthusiast premiumscripts's Avatar
    Join Date
    Aug 2009
    Location
    PremiumScripts.com
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're showing the apache error log, you need to show the php error log, it's a different file.

    If you don't have access, you can try adding this to the top of the file:

    PHP Code:
    error_reporting(E_ALL);
    ini_set('display_errors'1); 
    And then refresh the page, it may give you a clue.

  4. #4
    SitePoint Member
    Join Date
    Dec 2007
    Location
    Utah
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added the code to the top of the index.php file (after the initial <?php), premiumscripts, saved it, and reran the file. Apache still died after throwing the same message. I can't find the php error log, though. Can you tell me where that is usually stored? Thanks for the reply!

  5. #5

  6. #6
    SitePoint Member
    Join Date
    Dec 2007
    Location
    Utah
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Boo-yah! You rock, TomB! Thanks so much for the links! I don't know how the search I did on the forums didn't show any of these. Thanks, again!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •