This is probably a silly question but I cannot figure out with my data is not showing in the table created.
So the database looks like this and the connection to it, and it spits out the data just fine.
So I want to use the data inside some html but it goes wrong somewhere.
the code and the "result"
the inspect view of the html, is the php part supposed to look like it is commented out?
I'm very new at this, it's my second day using html, css, sql, and php.
I cannot see any mistakes but obviously something is wrong, do you know?
[Solved] database doesn't show on table
Moderators: egami, macek, gesf
What errors have you got?
Why didn't you post the code rather than an image (use the </> button for code), although I will give you marks for providing a clear image, but code is easier to copy and paste than type out from an image, this means you will be more likely to get a response.
Also, when posting a question, let us know what you have tried, what results you are getting - although the code may not be doing what you expect or want it to do, it will do something. Debugging is usually finding out how far along your code the parser gets before it throws its bytes out of the cpu, this will help understand why it went wrong.
I'd suggest learning from another sources since much of what you have there is out of date, not HTML, not css and bad practice, including the use of MySQLi especially procedural style.
You should be looking for a tutorial which uses PDO and prepared statements for databases, uses external stylesheets.
Make sure that you validate your HTML and CSS before posting as many faults can be corrected by doing this.
Why didn't you post the code rather than an image (use the </> button for code), although I will give you marks for providing a clear image, but code is easier to copy and paste than type out from an image, this means you will be more likely to get a response.
Also, when posting a question, let us know what you have tried, what results you are getting - although the code may not be doing what you expect or want it to do, it will do something. Debugging is usually finding out how far along your code the parser gets before it throws its bytes out of the cpu, this will help understand why it went wrong.
I'd suggest learning from another sources since much of what you have there is out of date, not HTML, not css and bad practice, including the use of MySQLi especially procedural style.
You should be looking for a tutorial which uses PDO and prepared statements for databases, uses external stylesheets.
Make sure that you validate your HTML and CSS before posting as many faults can be corrected by doing this.
I really appreciate your patience. It's probably my own fault that the code is outdated, since I tried different ways to display it when it didn't work out with my "real code". The idea behind this being that maybe if I use code that is less complicated/automated I would be able to see where the mistake is made.hyper wrote: ↑Thu Apr 30, 2020 8:18 amWhat errors have you got?
Why didn't you post the code rather than an image (use the </> button for code), although I will give you marks for providing a clear image, but code is easier to copy and paste than type out from an image, this means you will be more likely to get a response.
Also, when posting a question, let us know what you have tried, what results you are getting - although the code may not be doing what you expect or want it to do, it will do something. Debugging is usually finding out how far along your code the parser gets before it throws its bytes out of the cpu, this will help understand why it went wrong.
I'd suggest learning from another sources since much of what you have there is out of date, not HTML, not css and bad practice, including the use of MySQLi especially procedural style.
You should be looking for a tutorial which uses PDO and prepared statements for databases, uses external stylesheets.
Make sure that you validate your HTML and CSS before posting as many faults can be corrected by doing this.
also I had an if statement to check if there were any rows in the database before running the while loop to get the data, but I removed it so I had the just base minimum of code to get errors from. I have added it back in again, and as you can see it displays in the html box. I don't understand why it breaks in the middle of the check to see if there is data in the database,
Code: Select all
?php
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)) {
?>
cpu.php
Code: Select all
<?php
include_once 'includes/dbh.inc.php';
$sql = "SELECT * FROM cpu;";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Super</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<a href="index.html" class="header-brand">Super</a>
<nav>
<ul>
<li><a href="Build.html">Build</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
<a href="#" class="header-link">Link</a>
</nav>
</header>
<main>
<div class="wrapper">
<section class="builds-links">
<h2>CPU</h2>
<div class="builds-specifications">
<ul>
<?php
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)) {
?>
<li><a><?php echo $row['brand']; ?></a></li>
<li><a><?php echo $row['name']; ?></a></li>
<li><a><?php echo $row['socket']; ?></a></li>
<li><a><?php echo $row['architecture']; ?></a></li>
<li><a><?php echo $row['family']; ?></a></li>
<li><a><?php echo $row['cores']; ?></a></li>
<li><a><?php echo $row['ghz']; ?></a></li>
<li><a><?php echo $row['price']; ?></a></li>
<li><a><?php echo $row['stock']; ?></a></li>
<?php
}
}
?>
</ul>
</div>
</section>
</div>
</main>
style.css
Code: Select all
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/*code*/
*{
text-decoration: none;
}
main{
padding-top: 100px;
}
header{
position: fixed;
top: 0;
right: 0;
left: 0;
background-color: #fff;
width: 100%;
height: 100px;
}
header .header-brand{
font-family: arial;
font-size: 24px;
font-weight: 900;
color: #111;
text-transform: capitalize;
display: block;
margin: 0 auto;
text-align: center;
padding: 20px 0;
}
header nav ul{
display: block;
margin: 0 auto;
width: fit-content;
}
header nav ul li{
display: inline-block;
float: left;
list-style: none;
padding: 0 16px;
}
header nav ul li a{
font-family: arial;
font-size: 16px;
color: #111;
text-transform: capitalize;
}
header .header-link{
display: none;
}
@media only screen and (min-width: 1000px){
header .header-brand{
margin: 31px 0;
text-align: left;
line-height: 38px;
padding: 0 20px 0 40px;
border-right: 3px solid #111;
float: left;
}
header nav ul{
margin: 20px 0 0 20px;
float: left;
}
header nav ul li a{
line-height: 60px;
}
header .header-link{
display: block;
font-family: arial;
font-size: 16px;
color: #111;
text-transform: capitalize;
line-height: 38px;
border: 1px solid #111;
float: right;
margin-right: 40px;
margin-top: 30px;
padding: 0 20px;
}
}
/*index*/
.index-banner{
width: 100%;
height: calc(100vh - 100px);
background-image: url(img/banner.png);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
display: table;
}
.vertical-center{
display: table-cell;
vertical-align: middle;
}
.index-banner h2{
font-family: arial;
font-size: 60px;
font-weight: 900;
line-height: 70px;
color: #fff;
text-align: center;
text-shadow: 2px 2px 8px #111;
}
.index-banner h1{
font-family: arial;
font-size: 28px;
font-weight: 100;
font-style: italic;
line-height: 40px;
color: #fff;
text-align: center;
text-shadow: 2px 2px 8px #111;
}
.index-links div{
margin: 16px 16px 0;
width: calc(100% - 32px);
height: 100px;
background-color: #f2f2f2;
}
.index-links div h3{
font-family: arial;
font-size: 28px;
font-weight: 600;
line-height: 100px;
color: #111;
text-align: center;
text-transform: uppercase;
}
@media only screen and (min-width: 1000px){
.wrapper{
width: calc(100% - 32px);
margin: 0 auto;
}
.index-banner{
height: 450px;
}
.index-banner h1{
display: block;
margin: 0 auto;
}
.index-links{
overflow: hidden;
}
.index-links div{
margin: 20px 10px 0;
height: 230px;
background-color: #f2f2f2;
float: left;
}
.index-boxlink-square{
width: calc(25% - 20px) !important;
}
.index-boxlink-rectangle{
width: calc(50% - 20px) !important;
}
.index-links div h3{
line-height: 30px;
}
}
/*builds*/
.builds-links{
overflow: hidden;
margin-bottom: 20px;
}
.builds-links h2{
font-family: arial;
font-size: 28px;
font-weight: 600;
margin-left: 10px;
color: #111;
text-transform: capitalize;
}
.builds-links .builds-link{
float: left;
width: calc(25% - 20px);
height: 230px;
margin: 20px 10px 0;
background-color: #e3e3e3;
}
.builds-links .builds-link p{
padding-top: 103px;
font-family: arial;
font-size: 24px;
font-weight: 600;
color: #111;
text-align: center;
text-transform: capitalize;
}
.builds-links .builds-specifications{
float: left;
width: calc(25% - 20px);
height: 230px;
margin: 20px 10px 0;
background-color: #e3e3e3;
}
.builds-links .builds-specifications ul li a{
font-family: arial;
font-size: 16px;
font-weight: ;
color: #111;
text-align: center;
text-transform: capitalize;
}
@media only screen and (max-width: 1000px){
.builds-links .builds-link{
float: left;
width: calc(100% - 32px);
height: 100px;
margin: 16px 16px 0;
background-color: #e3e3e3;
}
.builds-links .builds-link p{
padding-top: 38px;
font-family: arial;
font-size: 24px;
font-weight: 600;
color: #111;
text-align: center;
text-transform: capitalize;
}
.builds-links h2 {
padding-left: 5px;
}
}
/*build*/
.build1 h2{
font-family: arial;
font-size: 28px;
font-weight: 600;
color: #111;
text-align: center;
text-transform: capitalize;
}
.build1 video{
display: block;
margin: 0 auto;
padding: 30px 0;
}
.build1 article h3{
font-family: arial;
font-size: 28px;
font-weight: 600;
color: #111;
text-transform: capitalize;
padding-bottom: 20px;
}
.build1 article div p{
font-family: arial;
font-size: 16px;
font-weight: 600;
line-height: 24px;
color: #111;
text-transform: capitalize;
column-count: 3;
column-gap: 30px;
}
/*footer*/
footer{
width: calc(100% - 80px);
padding: 40px 40px;
margin-top: 20px;
background-color: #111;
overflow: hidden;
}
footer ul{
width: fit-content;
float: left;
padding-left: 20px;
}
footer ul li{
display: block;
font-family: arial;
font-size: 16px;
line-height: 30px;
color: #fff;
list-style: none;
}
footer ul li a{
font-family: arial;
font-size: 16px;
color: #fff;
line-height: 30px;
}
.footer-links-second{
display: none;
}
.footer-socialmedia{
width: 60px;
float: right;
}
.footer-socialmedia img{
width: 100%;
margin-bottom: 10px;
}
@media only screen and (min-width: 1000px){
.footer-links-second{
display: block;
}
footer ul{
padding-left: 30px;
}
footer ul li p{
font-family: arial;
font-size: 16px;
color: #fff;
line-height: 30px;
text-transform: uppercase;
}
}
- Attachments
-
- cpuphp.png (38.83 KiB) Viewed 668 times
Check you error log, you can find the location of the error log by running
Code: Select all
<?php
phpinfo();
It gives a path but it doesn't exist, also using xampp control panel v3.2.4 I can click logs and php_error_log which also says the path doesn't existhyper wrote: ↑Fri May 01, 2020 8:07 amCheck you error log, you can find the location of the error log by runningCode: Select all
<?php phpinfo();
I have figured it out, so when running the code you need to use a program to simulate the server side, which I thought I was doing correctly but it turned out I wasn't so using the propper url worked.
http://localhost/php/cpu.php instead of file:///C:/xampp/htdocs/php/cpu.php
http://localhost/php/cpu.php instead of file:///C:/xampp/htdocs/php/cpu.php