<?php
include ("db.php");
session_start();
$user = $_SESSION["user"];
if (isset($_POST["submit"])) {
$target_dir = "pics/";
$target_file = $target_dir . basename($_FILES["img"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
//check if there was an error
if ($uploadOk == 0) {
echo "The file couldnt be upload, please try again";
} else {
if (move_uploaded_file($_FILES["img"]["tmp_name"], $target_file)) {
echo "The file has been uploaded";
} else {
echo "Sorry there was a error";
}
}
$img = $_FILES['img']['name'];
$title = $_POST["cardname"];
$info = $_POST["description"];
$insta = $_POST["insta"];
$snap = $_POST["snap"];
$code = $_POST["code"];
$bg = $_POST["bg"];
$discord = $_POST["discord"];
$sql = "SELECT * FROM cards WHERE code = '".$code."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "Please pick a new id, that one is already taken";
} else {
$sql = "INSERT INTO cards (title, user, link, code, image, description, likes, snap, insta, yt, bg, discord)
VALUES ('$title', '$user', '$link', '$code', '$img', '$info', '0', '$snap', '$insta', '$user', '$bg', '$discord')";
if ($conn->query($sql) === TRUE) {
echo "New card created!";
} else {
echo "There was an error";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="main.css">
<title>Personal cards for your social media or business | SocialCard</title>
</head>
<body>
<style>
.white {
color: white !important;
}
</style>
<div class="jumbotron">
<div class="container text-center">
<h1 class="big">Cards</h1><br>
<?php
$sql3 = "SELECT * FROM cards WHERE user = '$user'";
$result3 = $conn->query($sql3);
if($result3->num_rows > 0) {
//output cards
while($row = $result3->fetch_assoc()) {
?>
<div class="col-sm-4">
<div class="card">
<div class="card-img-top">
<img alt="" src="pics/<?php echo $img; ?>">
</div>
</div>
</div>
</div>
<?php
}
}
?>
<br>
<?php echo $_SESSION["user"]; ?>
<hr>
<div class="card">
<div class="card-body text-center">
<h4>Card Name:</h4>
<form action="" enctype="multipart/form-data" method="post">
<br>
<input type="text" name="cardname">
<br>
<br>
<h4>Profile Image:</h4>
<input type="file" name="img">
<br>
<br>
<h4>Short info:</h4>
<input type="text" name="description">
<br>
<br>
<h4>Instagram link:</h4>
<br>
<input type="text" name="insta">
<br>
<br>
<h4>Snapchat link:</h4>
<br>
<input type="text" name="snap">
<br>
<br>
<h4>Discord Tag:</h4>
<br>
<input type="text" name="discord">
<br>
<br>
<h4>Background Color:</h4>
<br>
<input type="text" name="bg" placeholder="#hexcode">
<br>
<br>
<h4>Unique Id:</h4>
<br>
<input type="text" placeholder="Create One :), remember it" name="code" required>
<br>
<br>
<button type="submit" name="submit" class="btn btn-lg btn-primary">Create Card</button>
<p>To get to your card go to: social-card.pw/view.php?code=youruniqueid</p>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="card bg-dark">
<div class="card-content white">
<h1 class="text-center font1">Purchase Premium</h1>
<p class="text-center">Nothing here yet</p>
<script data-cfasync='false' type='text/javascript' src='//p258030.clksite.com/adServe/banners?tid=258030_546328_0&type=footer&size=37'></script>
</div>
</div>
</div>
</body>
</html>
这是我目前的php和html代码,我必须犯一个小错误,因为我每次去看它时我屏幕上显示的唯一东西是顶部的jumbotron,里面有测试“卡”,请帮我!我确定这只是一个小错误,我无法找到答案。
我假设它的PHP代码,如果有人可以帮助那将是伟大的。
答案 0 :(得分:1)
假设您的查询实际上正在检索卡片,则显示器不会从返回的结果中获取图像...
while($row = $result3->fetch_assoc()) {
?>
<div class="col-sm-4">
<div class="card">
<div class="card-img-top">
<img alt="" src="pics/<?php echo $img; ?>">
</div>
</div>
</div>
</div>
<?php
}
使用$img
图片并非使用$row
中的数据。
你应该有类似......
echo $row['image'];
我还不确定循环中是否有额外的</div>
,您可能需要将最后一个</div>
移出循环,但请使用生成的源检查。
答案 1 :(得分:0)
将session_start()
放在第一行,即:
session_start();
include ("db.php");
session_start();
必须在 任何其他行或操作之前启动。
<div class="jumbotron">
<div class="container text-center">
<h1 class="big">Cards</h1><br>
<?php
$sql3 = "SELECT * FROM cards WHERE user = '$user'";
$result3 = $conn->query($sql3);
if($result3->num_rows > 0) {
//output cards
while($row = $result3->fetch_assoc()) {
?>
<div class="col-sm-4">
<div class="card">
<div class="card-img-top">
<img alt="" src="pics/<?php echo $row['image']; ?>">
</div>
</div>
</div>
<?php
}
}
?>
检查所有结束div