Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PHP query problem?

    Code:
    Warning: mysqli_query() expects parameter 1 to be mysqli, null given in D:\Hosting\7186816\html\sites\hardwood\index.php on line 8
    I am getting this message. Any idea why?

    Code:
    <?php
    session_start();
    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 Nav 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);
    
    
    ?>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Installing Hardwood Flooring - Self Install Flooring - Laying Flooring </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="Description" content="How to Install Hardwood Flooring">
    <meta name="KeyWords" content="Laying hardwood floors, why hardwood flooring, concrete">
    <meta name="Author" content="John P">
    <link rel=stylesheet href=style.css>
    <!--[if lt IE 9]>
    <script src=http://html5shiv.googlecode.com/svn/trunk/html5.js></script>
    <![endif]-->
    </head>
    
    
    
    <body>
    Hi
    </body>
    
    </html>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Your variable $myConnection is null, not a valid mysqli resource. Check your connect_to_mysql.php script.


  •  

    Posting Permissions

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