Code showing up at top of webpage

I created a website that sells jewelry using html, css, and php. When I add products to the database what I put in comes up at the top of the page. How do I stop this from showing up? Could this have something to do with the php on my add inventory page?

We have no idea what you saw when you ran your code. You will need to either post a copy/paste or a picture of what you saw and if you cannot determine what is causing the incorrect result, you will need to post all the relevant code needed to reproduce the problem.

Here is the code for the page:

<?php
error_reporting(E_ALL);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);

include_once("../storescripts/connect_to_mysql.php");
$con = mysqli_connect("$db_host","$db_username","$db_pass","$db_name");
if (mysqli_connect_errno()) {
	printf("Connect failed: %s\n", mysqli_connect_errno());
	exit();
}

if(isset($_POST['button'])) {

$item_number = mysqli_real_escape_string($con, $_POST['item_number']);
$price = mysqli_real_escape_string($con, $_POST['price']);
$category = mysqli_real_escape_string($con, $_POST['category']);
$desc = mysqli_real_escape_string($con, $_POST['description']);
$qty = mysqli_real_escape_string($con, $_POST['qty']);

// See if that product name is an identical match to another product in the system
	$sql = ("SELECT id FROM products WHERE item_number='$item_number' LIMIT 1");
	$result = mysqli_query($con, $sql);
	$productMatch = mysqli_num_rows($result); // count the output amount
    if ($productMatch > 0) {
		echo 'Sorry you tried to place a duplicate "item_number" into the system, <a href="inventory_list.php">click here</a>';
		exit();
	}
	//Add to inventory now

$sql = "INSERT INTO products (item_number, price, category, description, qty, date_added)
	VALUES (?,?,?,?,?,?)";
$stmt = mysqli_stmt_init($con);
if(!mysqli_stmt_prepare($stmt, $sql)) {
	echo "sql error";
} else {
	mysqli_stmt_bind_param($stmt, "ssssss", $item_number, $price, $category, $desc, $qty, date("Y-m-d H:i:s"));

	mysqli_stmt_execute($stmt);
	echo mysqli_stmt_error($stmt);
	$result = mysqli_stmt_get_result($stmt);
	$pid = mysqli_insert_id($con);
	// Place image in the folder
	$newname = "$pid.jpg";
	move_uploaded_file( $_FILES['fileField']['tmp_name'], "../pictures/inventory/$newname");
}
}
?>
<?php
$product_list = '';
include_once("../storescripts/connect_to_mysql.php");
	$con = mysqli_connect("$db_host","$db_username","$db_pass","$db_name");
$sql = "SELECT * FROM products ORDER BY date_added DESC";
$result = mysqli_query($con, $sql);
$product_count = mysqli_num_rows( $result);
if ($product_count > 0) {
	while($row = mysqli_fetch_array($result)){
             $id = $row["id"];
			 $item_number = $row["item_number"];
			 $price = $row["price"];
			 $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));

			 $qty = $row["qty"];
	}
} else {
		$product_list = "You Have No Items In Inventory";
	}
?>
<?php
// Delete Item Question to Admin, and Delete Product if they choose
if (isset($_GET['deleteid'])) {
	echo 'Do you really want to delete product with ID of ' . $_GET['deleteid'] . '? <a href="inventory_list.php?yesdelete=' . $_GET['deleteid'] . '">Yes</a> | <a href="inventory_list.php">No</a>';
	exit();
}
if (isset($_GET['yesdelete'])) {
	// remove item from system and delete its picture
	// delete from database
	$id_to_delete = $_GET['yesdelete'];
	$sql = mysqli_query("DELETE FROM products WHERE id='$id_to_delete' LIMIT 1") or die (mysqli_error());
	// unlink the image from server
	// Remove The Pic -------------------------------------------
    $pictodelete = ("../inventory_images/$id_to_delete.jpg");
    if (file_exists($pictodelete)) {
       		    unlink($pictodelete);
    }
	header("location: inventory_list.php");
    exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="samuel jaycox">
<title>Inventory List</title>
<link rel="stylesheet" href="../style.css" type="text/css" media="screen" />
<link rel="shortcut icon" type="image/png" href="pictures/pinky.png">
</head>
<body>
<div align="center" id="mainWrapper">
  <div id="pageContent"><br />
    <div align="right" style="margin-right:32px;"><a href="inventory_list.php#inventoryForm">+ Add New Inventory Item </a></div>
<div align="left" style="margin-left:24px;">
      <h2>Inventory list</h2>
      <?php echo $product_list; ?>
    </div>
    <hr />
    <a name="inventoryForm" id="inventoryForm"></a>
    <h3>
    &darr; Add New Inventory Item Form &darr;
    </h3>
    <form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myForm" method="POST">
    <table width="90%" border="0" cellspacing="0" cellpadding="6">
      <tr>
        <td width="20%" align="right">Item Number</td>
        <td width="80%"><label>
          <input name="item_number" type="text" id="item_number" size="64" />
        </label></td>
      </tr>
      <tr>
        <td align="right">Product Price</td>
        <td><label>
          $
          <input name="price" type="text" id="price" size="12" />
        </label></td>
      </tr>
      <tr>
        <td align="right">Category</td>
        <td><label>
          <select name="category" id="category">
          <option value="Bracelets">Bracelet</option>
		  <option value="Necklace">Necklace</option>
		  <option value="Earring">Earring</option>
		  <option value="Childrens">Childrens</option>
		  <option value="Sets">Sets</option>
		  <option value="Rosary">Rosary</option>
		  <option value="Accessories">Accessories</option>
		  </select>
		</label>
	  </tr>
      <tr>
        <td align="right">Description</td>
        <td><label>
          <textarea name="description" id="description" cols="64" rows="20"></textarea>
        </label></td>
      </tr>
		 <tr>
        <td width="20%" align="right">Qty</td>
        <td width="80%"><label>
          <input name="qty" type="text" id="qty" size="9" />
        </label></td>
      </tr>
      <tr>
        <td align="right">Product Image</td>
        <td><label>
          <input type="file" name="fileField" id="fileField" />
        </label></td>
      </tr>
			<br />
      <tr>
        <td>&nbsp;</td>
        <td><label>
          <input class="button" type="submit" name="button" id="button" value="Submit"/>
        </label></td>
      </tr>
    </table>
    </form>
    <br />
  <br />
	<button <a href="logout.php" class="button">Logout</a>Logout </button>
  </div>
</div>
</body>
</html>

What I see when I run my page is:

Connection openedPB000322.00Soft colored 6mm bicone bracelet with 6mm glass pearls, 4mm white opal rondelles and seed beads running along the top. Lobster claw clasp. 7 1/4inch BraceletsPB000221,008mm pale pink glass pearls, accented by 4mm glass grey pearls, clear glass bugle beads, and 4mm glass fuchsia bicones. Antiqu silver toggle clasp. 8 1/2 inch.BraceletsPB00048.00Cute and stylish multi-colored button bracelet. BraceletsPB000512.00Solid blue bracelet made with glass 8mm blue crackle beads accented with glass blue seed beads.BraceletsPB00066.00A combination of 8mm yellow and green crackle beads accented with 3 ceramic yellow butterflies on a stretch elastic chord.BraceletsPB00077.003 shades of 8mm glass pearls accented with 2 charms. One a pink teardrop. the other a square charm. BraceletsPB00088.006mm glass rondelles in the colors of black diamond, pink and crystal with a heart shaped dangle with pink stone.BraceletsPB00096.008mm Fuchsia and lavender crackle bead bracelet strung on stretch elastic chord. Simple but fun!BraceletsPB00108.006mm crystal rondelle, 6mm grey glass pearls followed by an 8mm glass white pearl. This bracelet would compliment any dress attire.BraceletsPB00118.006mm crystal rondelle along with 8mm gold glass pearl with a gold charm that reads "focus"BraceletsPB00128.006mm round crystal with 4mm blue glass cube beads.BraceletsPB00138.00A rainbow delight! This bracelet is made with all colors of the rainbow. Each glass bicone is 6mm separated by rondelle spacer beads.BraceletsPB00148.008mm glass crackle beads in light pink and crystal, separated by antique gold spacers. strung on elastic stretch chord.BraceletsPB00158.008mm gold and coral glass pearls, separated by antique gold flat spacers. Charm consists of 1 8mm glass coral pearl, 6mm white pearl and rondelle spacer with crystal stones. strung on elastic stretch chord.BraceletsPB00169.00This unique stretchy bangle bracelet is made with 8mm light gold glass pearls, 8mm pink pearls, separated by gold rondelle spacers with crystal stones. Accent beads are glass oval beads.BraceletsPB001710.008mm and 6mm glass pearls in white, light blue, lavender, turquoise and purple, separated by AB rondelle spacers.BraceletsPB00188.006mm red glass pearls and 6mm dark purple rondelle with a fun dangle charm of handcuffs.BraceletsPB00198.008mm clear glass and fuchsia crackle beads with a antique silver stone cross.Bracelets

This is all the information I put into my database for all the items.

Also I am using xampp and apache for my server.

There’s nothing in the posted code that would output that and I mean nothing (you are not using the data that was retrieved from the SELECT query) and the output you are getting doesn’t exist in the posted code.

Either the code you are running isn’t what you have posted or the connect_to_mysql.php code is where this output is coming from (which you should know since this is your code running on your system.)

This is the code for the actual bracelet page:

<?php
error_reporting(E_ALL);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1)
?>
<?php

	// Connect to the MySQL database
    include_once("storescripts/connect_to_mysql.php");
    $con = mysqli_connect("$db_host","$db_username","$db_pass","$db_name");

if (mysqli_connect_errno()) {
	printf("Connect failed: %s\n",
	mysqli_connect_errno());
	exit();

}
	 $id = '';
     if( isset( $_GET['id'])) {
       $id = $_GET['id'];
}
	   $sql = "SELECT * FROM products WHERE category = 'Bracelets'";
     $result = mysqli_query($con, $sql);
	   $resultCheck = mysqli_num_rows($result);

     if ($result->num_rows > 0) {

// output data of each row
while($row = $result->fetch_assoc()) {
    echo $item_number[] = $row["item_number"];
    echo $price[] = $row["price"];
    echo $desc[] = $row["description"];
    echo $category[] = $row["category"];
}
} else {
    echo "0 results";

}
$con->close();
?>
<!DOCTYPE html>
<html>
<head>
	<title>Bracelets</title>
	<meta charset="utf-8">
	<meta http-equiv="x=UA-comparable" content="IE-edge">
	<meta name="description" content="Pinky's Pearls is a website where one of a kind jewelry designed by Nichole <q>Nicki</q> can be seen and purchased">
	<meta name="keywords" content="jewelry, beads, bracelets, rings, pendants, necklaces, pearls, crystal">
	<meta name="viewpoint" content="width=device-width, initial-scale=1">
	<meta name="author" content="samuel jaycox">
	<link rel = "stylesheet" href="style.css">
	<link rel="shortcut icon" type="image/png" href="c:/xampp/htdocs/pinkys_pearls/pictures/pinky.png">
</head>
<body>
	<div id="wrapper">
	<div id="banner-wrapper">
	<!---Company Header-->
		<header>
      <div id="header">
        <?php include_once("templates/template_header.php"); ?>
				<h1 class="main_header">Bracelets</h1>
				<audio autoplay="autoplay" loop="loop" id="background-music">
					<source src="music/Albinoni-adagio-in-g-minor-acoustic-guitar.mp3" type="audio/mpeg">
					<source src="music/Albinoni-adagio-in-g-minor-acoustic-guitar.wav" type="audio/wav">
				</audio>
	    </div>
		</header>
<!---end of Company Header-->
		<br>
	<?php include_once("templates/template_navigation.php"); ?>
		<br>
		<br>
		<br>
<!--Start Comment page Body Content-->
<div id="body-content">
	<div class="bracelet_body">
		<?php
				for ($i=0; $i <sizeof($item_number) ; $i++) {
		?>
		<table width="100%" border="2" cellspacing="0" cellpadding="15">
  <tr>
    <td width="14%" valign="top">
		<img src="pictures/inventory/<?php echo $item_number[$i]; ?>.jpg" width="180" height="188" alt="<?php echo $item_number[$i]; ?>" /><br />
      	<a href="pictures/inventory/<?php echo $item_number[$i]; ?>.jpg">View Full Size Image</a></td>
    <td width="86%" valign="top">
		<h3 class="Item"><?php echo $item_number[$i]; ?></h3>
      <p padding="10">Price: <?php echo "$".$price[$i]; ?><br />
        <br />
        Description: <?php echo $desc[$i]; ?>
<br />
		 Category: <?php echo $category[$i]; ?>
        </p>
      <form  id="form1" name="form1" method="post" action="cart.php">
        <input type="hidden" name="pid" id="pid" value="<?php echo $item_number[$i]; ?>" />
        <br />
        <input class="button" type="submit" name="button" id="button" value="Add to Shopping Cart" />
      </form>
      </td>
	</tr>

</table>
<?php
       }
 ?>
	</div>
</div>
<!--end of Comment body-->
<footer>
		<div class="icon-text">
			<div class="icon-text-text">
				<ul class="footer-nav">
					<li><a href="tearms.php">Tearms and Conditions</a></li>
					<li><a href="shipping_info.php">Shipping Information</a></li>
				</ul>
			</div>
		</div>
		<div class="icon-text-icon">
			<p class="email_text">Follow Me On</p>
			<div class="social-icon">
				<a href="#">
				<img class="social-icon" src="icons/facebook.png" alt="Facebook" height="45" width="45"></a>
			</div>
		</div>
</footer>
<footer class="second">
		<p>&copy; All Rights Reserved</p>
</footer>
</body>
</html>

My connect_to_mysqli is the basic code to log into the database:

<?php
// Place db host name. Sometimes "localhost"
$db_host = "localhost:3306"; 
// Place the username for the MySQL database here 
$db_username = "root";  
// Place the password for the MySQL database here 
$db_pass = "uqu4g9cc!";  
// Place the name for the MySQL database here 
$db_name = "pinkys_pearls"; 

// Run the actual connection here  
$con = mysqli_connect("$db_host","$db_username","$db_pass","$db_name")  or die ("Error" .       mysqli_error($con));
	//check connection

mysqli_close($con)
              
?>

When the information I need from the database is shown on the page I get that giant block at the top and it comes out the way I want it on the remainder of the page. I put the first code thinking it may be the way it was being entered into the database.

Seriously kids. We cannot help you if you are not posting actual code and are not even looking at the code you have written or copied from somewhere.

Your code is echoing the values as they are being assigned to the arrays. Why do you even have those echo statements inside the while(){} loop and more importantly, why didn’t you look at your code and discover such an obvious cause of the problem?

Sponsor our Newsletter | Privacy Policy | Terms of Service