Skip to main content
Participant
July 18, 2017
Answered

Need Help with New Site

  • July 18, 2017
  • 3 replies
  • 490 views

Hi,
I'm building a new website and I'm really stuck. I built a product data base using php my admin and xampp. I successfully connected the site to the server but when I access it on google, it shows up that the site is not there. I think there is an error in my code but I can't figure out what. I'm trying to make an e-commerce site and this is so difficult. Can someone please tell me what is wrong. I think the error is in my action.php. Thanks to whoever can solve this.

index.html

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>True Filters and Membranes</title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<script src="action.php"></script>

<script src="main.js"></script>

<script src= "db.php"></script>

<style>

/* LOGIN */

.login {

width: 300px;

background-color: #337AB7;

padding: 20px 10px;

color: #fff;

}

/* CART ITEMS */

.cart-items {

width: 300px;

padding: 10px;

}

.cart-items li {

padding: 7px 0 7px 0;

border-top: 1px solid #ccc;

}

.cart-items li:first-child {

border-top: none;

}

</style>

</head>

<body>

<nav class="navbar navbar-default">

<div class="container-fluid">

<div class="navbar-header">

<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">

<span class="sr-only">Toggle navigation</span>

<span class="icon-bar"></span>

<span class="icon-bar"></span>

<span class="icon-bar"></span>

</button>

<a class="navbar-brand" href="#">True Filters and Membranes</a>

</div>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

<ul class="nav navbar-nav">

<li class="active" ><a href="#">Home</a></li>

<li><a href="#">Product</a></li>

</ul>

<form class="navbar-form navbar-left">

<div class="form-group">

<input type="text" class="form-control" placeholder="Search">

</div>

<button type="submit" class="btn btn-default">Submit</button>

</form>

<ul class="nav navbar-nav navbar-right">

<li class="dropdown">

<a href="#" class="dropdown-toggle" data-toggle="dropdown">Login <span class="caret"></span></a>

<div class="dropdown-menu login">

<div class="panel-heading">Login</div>

<div class="panel-heading">

<label for="email">Email</label>

<input type="email" class="form-control" id="email" required/>

<label for="email">Password</label>

<input type="password" class="form-control" id="password" required/>

<p><br/></p>

<a href="#" style="color:white; list-style:none;">Forgotten Password</a><input type="submit" class="btn btn-success" style="float:right;" id="login" value="Login">

</div>

</div>

<!-- end panel -->

</li>

<!-- end dropdown -->

<li class="dropdown">

<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-shopping-cart"></span> 7 - Items<span class="caret"></span></a>

<ul class="dropdown-menu cart-items">

<!-- start cart item -->

<li>

<span class="item">

<span class="item-left">

<img src="http://lorempixel.com/50/50/" alt="" />

<span class="item-info">

<span>Item name</span>

<span>23$</span>

</span>

</span>

<span class="item-right">

<button class="btn btn-xs btn-danger pull-right">x</button>

</span>

</span>

</li>

<!-- end cart item -->

<!-- start cart item -->

<li>

<span class="item">

<span class="item-left">

<img src="http://lorempixel.com/50/50/" alt="" />

<span class="item-info">

<span>Item name</span>

<span>23$</span>

</span>

</span>

<span class="item-right">

<button class="btn btn-xs btn-danger pull-right">x</button>

</span>

</span>

</li>

<!-- end cart item -->

<!-- start cart item -->

<li>

<span class="item">

<span class="item-left">

<img src="http://lorempixel.com/50/50/" alt="" />

<span class="item-info">

<span>Item name</span>

<span>23$</span>

</span>

</span>

<span class="item-right">

<button class="btn btn-xs btn-danger pull-right">x</button>

</span>

</span>

</li>

<!-- end cart item -->

</ul>

<!-- end dropdown-menu -->

</li>

<!-- end dropdown -->

</ul>

<!-- end navbar-right -->

</div><!-- end navbar-collapse -->

</div><!-- end container-fluid -->

</nav>

<!-- end navbar -->

</body>

</html>

<p><br/></p>

<p><br/></p>

<p><br/></p>

<div class="container-fluid">

  <div class="row">

  <div class="col-md-1"></div>

  <div class="col-md-2">

  <div id="get_category">

  </div>

  <!--<div class="nav nav-pills nav-stacked">

  <li class="active"><a href="#"><h4>Categories</h4></a></li>

  <li><a href="#">Categories</a></li>

  <li><a href="#">Categories</a></li>

  <li><a href="#">Categories</a></li>

  <li><a href="#">Categories</a></li>

  </div>-->

  <div class="nav nav-pills nav-stacked">

  <li class="active"><a href="#"><h4>Brand</h4></a></li>

  <li><a href="#">Categories</a></li>

  <li><a href="#">Categories</a></li>

  <li><a href="#">Categories</a></li>

  <li><a href="#">Categories</a></li>

  </div>

  </div>

<div class="col-md-8">

  <div class="panel panel-info">

  <div class="panel-heading">Products</div>

  <div class="panel-body">

  <div class="col-md-4">

  <div class="panel panel-info">

  <div class="panel-heading"> True Ultra Filter</div>

  <div class="panel-body">

  <img src="product_images/Icon.jpg"/>

  </div>

  <div class="panel-heading"> $500.00

  <button style="float:right;" class="btn btn-danger btn-xs">Add to Cart</button></div>

  </div>

  </div>

  </div>

  <div class="panel-footer">&copy;2017</div>

  </div>

  </div>

  <div class="col-md-1"></div>

  

  </div>

MAIN.JS

(document) .ready(function() {

  cat () {

  function cat () {

  $.ajax ({

  url :     "action.php"

  method:   "POST"

  data     : {category:1},

  success  :  function (data)

  $("#get_category").html (data);

  })

}

  

   })

  // JavaScript Document

ACTION.PHP

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<title>True Filters and Membranes action.php</title>

</head>

<?php

  include "db.php";

  if (isset ($_POST["category"])) {

  $category_query = "SELECT * FROM categories";

  $run_query = mysql_query($con,$category_query);

  echo"

  <div class='nav nav-pills nav-stacked'>

  <li class='active''><a href='#'><h4>Categories</h4></a></li>

  ";

  if (mysql_num_rows ($run_query) >0) {

  while ($row = mysqli_fetch_array ($run_query)) {

  $cid =$row["cat_id"];

  $cat_name = $row["cat_title"];

  echo "

  <li><a href='#'>$cat_name</a></li>

  ";

  }

  echo "</div>";

  }

  }

  ?>

<body>

</body>

</html>

DB.PHP

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<title>True Filters and Membranes DB.PHP</title>

</head>

<body>

<?php

  $servername = "localhost"

  $username   = "root"

  $password   = "";

  $db = "TrueFiltersandMembranes";

// Create Connection

$con = mysqli_connect ($servername, $username, $password, $db);

// Check Connection

if (!$con) {

  die ("Connection failed: " .mysqli_connect_error());

}

?>

</body>

</html>

    This topic has been closed for replies.
    Correct answer Nancy OShea

    I think I'm going to switch to adobe muse because I'm having a lot of trouble on my own. Do you think this is a good idea?


    David Powers' Tutorials on Lynda.com

    Nancy

    3 replies

    Nancy OShea
    Community Expert
    Community Expert
    July 18, 2017

    When you open the site on your localhost, do you get any MySQL errors?

    Is Xampp on?

    Are Apache & PHP services running?

    Did you define your local testing server correctly in DW?

    Nancy

    Nancy O'Shea— Product User & Community Expert
    Legend
    July 18, 2017

    Problem 1 is your index.html needs to be index.php to run any php code.

    Problem 2, in your index page it should NOT be:

    <script src= "db.php"></script>

    it' should be:

    <php include('db.php'); ?>

    Problem 3, you only need the below in your db.php file:

    <?php

    $servername = "localhost"

    $username   = "root"

    $password   = "";

    $db = "TrueFiltersandMembranes";

    // Create Connection

    $con = mysqli_connect ($servername, $username, $password, $db);

    // Check Connection

    if (!$con) {

    die ("Connection failed: " .mysqli_connect_error());

    }

    ?>

    Problem 4, in your index page it should NOT be:

    <script src= "action.php"></script>

    it' should be:

    <php include('action.php'); ?>

    Problem 5, you are asking to see if a POST value has been set without posting anything, where does $_POST['category'] come from? Plus you only need the below in your action.php file

    It gets worse, you are mixing up mysqli and the now deprecated mysql - all function should be mysqli

    <?php

    if (isset ($_POST["category"])) {

    $category_query = "SELECT * FROM categories";

    $run_query = mysql_query($con,$category_query);

    echo"

    <div class='nav nav-pills nav-stacked'>

    <li class='active''><a href='#'><h4>Categories</h4></a></li>

    ";

    if (mysql_num_rows ($run_query) >0) {

    while ($row = mysqli_fetch_array ($run_query)) {

    $cid =$row["cat_id"];

    $cat_name = $row["cat_title"];

    echo "

    <li><a href='#'>$cat_name</a></li>

    ";

    }

    echo "</div>";

    }

    }

    ?>

    Legend
    July 18, 2017

    I would do a simple test. Insert the below into a new DW document and save it as test.php. Upload it to your server and browse out to it. If you have a database which uses the connection details below and a 'categories' table in that database with a column named 'cat_title' it should out put all the cat_titles.

    <?php

    // connect to database local

    $conn = new mysqli('localhost' , 'root' , '' , 'TrueFiltersandMembranes');

    //make sure special characters output correctly

    mysqli_query($conn, "SET NAMES 'UTF8'") or die("ERROR: ". mysqli_error($con));

    ?>

    <?php

    // list cat title

    $categories = $conn->query("SELECT * FROM categories") or die($conn->error);

    $num_rows = $categories->num_rows;

    echo $num_rows;

    ?>

    <?php while($row = $categories->fetch_assoc()) { ?>

    <h3><?php echo $row['cat_title']; ?></h3>

    <?php } ?>

    Participant
    July 18, 2017

    I think I'm going to switch to adobe muse because I'm having a lot of trouble on my own. Do you think this is a good idea?

    Jon Fritz
    Community Expert
    Community Expert
    July 18, 2017

    What do you mean by "when I access it on google, it shows up that the site is not there"?

    Are you talking about your site not appearing in Google.com's search results, or are you saying that when you go to yoursite.com using google Chrome, it doesn't appear?