表中未插入的数据使用的是php代码和mysqli

时间:2017-04-18 07:04:08

标签: php mysql mysqli

我做得很好,但没有得到更好的结果。使用php和mysqli命令我想插入数据。实际上,我正在将CMS系统作为实践工作。不知道如何做,请帮助!

这里的一些屏幕截图

post page

enter image description here

this is error i got

enter image description here

代码

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Personal Home Page</title>
    <!-- Bootstrap -->
	<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">

	<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
	<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
	<!--[if lt IE 9]>
		  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
		  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
		<![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>
  
	<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
	<script src="js/jquery-1.11.2.min.js"></script>

	<!-- Include all compiled plugins (below), or include individual files as needed --> 
	<script src="js/bootstrap.js"></script>
  </body>
</html>

<?php
include("includes/connect.php");

if (isset($_POST['submit']))
{
		$title=$_POST['title'];
		
		$author=$_POST['author'];
		$content=$_POST['content'];
		$image_name = $_FILES['image']['name'];
		$image_type = $_FILES['image']['type'];
	    $image_size = $_FILES['image']['size'];
	    $image_tmp = $_FILES['image']['tmp_name'];
		 
		 
		 if ($title=='' or $author=='' or $content==''){
			 echo "<script>alert('Do not let any field empty')</script>";
			  exit();
		 }
		if($image_type=="image/jpeg" or $image_type=="image/png" or $image_type=="image/gif"){
			
			if($image_size<=5000000){
				move_uploaded_file($image_tmp, "img/$image_name");
			}
		else{
			echo "<script>alert('image is greater')</script>";
		}
		}
		else{
			echo "<script>alert('image type is invalid')</script>";
		}
		
		$sql="INSERT INTO posts(post_title, post_author, post_img, post_content) VALUES($title,$author,$image_name,$content)";
		$link = mysqli_connect("localhost", "root", " ", "firstwebsitedb");
		if (mysqli_query($link,$sql)){
			echo "<script>alert('Post is Published')</script>";
		}
		else{
			echo "<script>alert('Post is not Published')</script>";
		}
}
?>

3 个答案:

答案 0 :(得分:0)

在查询中添加$request = $this->getRequest(); $view = new ViewModel(); $loginForm = new LoginForm('loginForm'); $loginForm->setInputFilter(new LoginFilter()); $error = array( 'status' => 'error', 'message' => 'Invalid Email or Password' ); if ($request->isPost()) { $data = $request->getPost(); $loginForm->setData($data); // echo "<pre>";print_r($data);exit; if ($data['email'] == '' || $data['password'] == '') { $this->flashmessenger()->addMessage("Please enter username and password ! "); } else { if ($loginForm->isValid()) { $data = $loginForm->getData(); $getid = $this->getMemberTable()->selectByid($data['email']); // echo "<pre>";print_r($getid);exit; if (!empty($getid)) { if ($getid->postal == 1) { $userPassword = new UserPassword(); $encyptPass = $userPassword->create($data['password']); $this->getAuthService()->getAdapter()->setIdentity($data['email'])->setCredential($encyptPass); $result = $this->getAuthService()->authenticate(); if ($result->isValid()) { $session = new Container('User'); $session->offsetSet('email', $data['email']); $session->offsetSet('user_id', $getid->id); $session->offsetSet('user_name', $getid->first_name); // Redirect to page after successful login $session = new Container('base'); if ($request->isXmlHttpRequest()) { $error['status'] = 'success'; $error['message'] = 'We got the posted data successfully.'; } else { $ref = $this->redirect()->toRoute('home'); $redirectUrl = $this->getRequest()->getHeader('HTTP_REFERER', $ref); $this->redirect()->toUrl($redirectUrl); } } else { if ($request->isXmlHttpRequest()) { $error['status'] = 'error'; $error['message'] = 'Invalid Email or Password'; } else { $this->flashmessenger()->addMessage("Invalid Username or Password "); // Redirect to page after login failure return $this->redirect()->toRoute('login', array( 'action' => 'index' )); } } } else { if ($request->isXmlHttpRequest()) { $error['status'] = 'error'; $error['message'] = 'Your Account is Deactivated!'; } else { $this->flashmessenger()->addMessage("Your Account is Deactivated!"); // Redirect to page after login failure return $this->redirect()->toRoute('login', array( 'action' => 'index' )); } } } else { if ($request->isXmlHttpRequest()) { $error['status'] = 'error'; $error['message'] = 'Record Does Not Exits, Please Register!'; } else { $this->flashmessenger()->addMessage("Record Does Not Exits, Please Register!"); // Redirect to page after login failure return $this->redirect()->toRoute('login', array( 'action' => 'index' )); } } // Logic for login authentication } else { // $error['status'] = 'error'; // $error['message'] = 'Invalid Email or Password'; // // $errors = $loginForm->getMessages(); $view->setVariable('loginForm', $loginForm); return $view; } } if ($request->isXmlHttpRequest()) { return new JsonModel($error); } else { // Redirect to page after login failure return $this->redirect()->toRoute('login', array( 'action' => 'index' )); } } // $view->setVariable('loginForm', $loginForm); // return $view; return array( 'loginForm' => $loginForm, 'flashMessages' => $this->flashMessenger()->getMessages() ); ,下面是插入语句:

$link

希望这会有所帮助!!!

答案 1 :(得分:0)

答案 2 :(得分:-1)

message(STATUS "Current CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}")

if("${CMAKE_SYSTEM_NAME}" STREQUAL "WIN98")
   set(libraryFileName ${QtDir}/bin/${packageName}.dll)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "LINUX")
   set(libraryFileName ${QtDir}/bin/${packageName}.so)
else
   message(ERROR "The system ${CMAKE_SYSTEM_NAME} is not supported.")
endif()

我认为您的数据库连接存在问题。您使用“”作为数据库密码。那里有空间。