私は大丈夫でしたが、結果は得られませんでした。 phpとmysqliコマンドを使ってデータを挿入したい。実際にCMSシステムを練習として作っています。それをどうやって助けてください!データがテーブルに挿入されていませんPHPコードとmysqli
ここにいくつかのスクリーンショットが
コードここ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
\t <meta http-equiv="X-UA-Compatible" content="IE=edge">
\t <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Personal Home Page</title>
<!-- Bootstrap -->
\t <link href="css/bootstrap.css" rel="stylesheet">
<link href="css/custom.css" rel="stylesheet">
<link rel="stylesheet" href="css/footer-distributed-with-address-and-phones.css">
\t <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
\t <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
\t <!--[if lt IE 9]>
\t \t <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
\t \t <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
\t \t <![endif]-->
</head>
<body>
<div class="jumbotron-2">
<h1 style="text-align:left">Write your New Post</h1>
<form class="form-horizontal" method="post" action="new_post.php" enctype="multipart/form-data">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Post Title*:</label>
<div class="col-sm-10">
<input type="name" class="form-control" name="title" placeholder="Title of Post">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Post Author*</label>
<div class="col-sm-10">
<input type="name" class="form-control" name="author" placeholder="Published By">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">File(img/vid:)*</label>
<div class="col-sm-10">
<input type="file" name="image" class="form-control" placeholder="image or video file">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Post Content:*</label>
<div class="col-sm-10">
<textarea rows="15" cols="100" name="content" class="form-control" placeholder="content goes here"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" name="submit" class="btn btn-success btn-lg" style="align-items:center">Publish</button>
<button type="reset" class="btn btn-danger btn-lg" style="align-items:center">Cancle</button>
</div>
</div>
</form>
</div>
<div style="background-color:#000000">
<div style="color:#FFFFFF" class="btn btn-danger btn-lg"><a href="backend.php">Backend</a></div>
</div>
\t <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
\t <script src="js/jquery-1.11.2.min.js"></script>
\t <!-- Include all compiled plugins (below), or include individual files as needed -->
\t <script src="js/bootstrap.js"></script>
</body>
</html>
<?php
include("includes/connect.php");
if (isset($_POST['submit']))
{
\t \t $title=$_POST['title'];
\t \t
\t \t $author=$_POST['author'];
\t \t $content=$_POST['content'];
\t \t $image_name = $_FILES['image']['name'];
\t \t $image_type = $_FILES['image']['type'];
\t $image_size = $_FILES['image']['size'];
\t $image_tmp = $_FILES['image']['tmp_name'];
\t \t
\t \t
\t \t if ($title=='' or $author=='' or $content==''){
\t \t \t echo "<script>alert('Do not let any field empty')</script>";
\t \t \t exit();
\t \t }
\t \t if($image_type=="image/jpeg" or $image_type=="image/png" or $image_type=="image/gif"){
\t \t \t
\t \t \t if($image_size<=5000000){
\t \t \t \t move_uploaded_file($image_tmp, "img/$image_name");
\t \t \t }
\t \t else{
\t \t \t echo "<script>alert('image is greater')</script>";
\t \t }
\t \t }
\t \t else{
\t \t \t echo "<script>alert('image type is invalid')</script>";
\t \t }
\t \t
\t \t $sql="INSERT INTO posts(post_title, post_author, post_img, post_content) VALUES($title,$author,$image_name,$content)";
\t \t $link = mysqli_connect("localhost", "root", " ", "firstwebsitedb");
\t \t if (mysqli_query($link,$sql)){
\t \t \t echo "<script>alert('Post is Published')</script>";
\t \t }
\t \t else{
\t \t \t echo "<script>alert('Post is not Published')</script>";
\t \t }
}
?>
あなたのDB接続があるショット? –
接続していることを確認してください – Akintunde007
http://php.net/manual/en/mysqli.select-db.php –