search

Home  >  Q&A  >  body text

Data cannot be inserted into the database

form.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>This is a title</title>
<style>
body{
background-color: transparent;
}
</style>
<script>
function foo() {
if(myform.title.value==""){
alert("Please fill in the title");
myForm.tital.focus ();
Return false;
}

if (myForm.Content.value == "") {
Alert ("Please fill in the content" );
myform.content.focus();
return false;
}

} }
</script>
</head>
< ;body>
<form method="post" action="new_post.php" name="myform" onsubmit="return foo();">
<h1>This is a news system< /h1>
<p>Title:<input type="text" name="title"></p>
<p>Content:<textarea cols="30" rows ="5" name="content"></textarea></p>
<p><input type="submit" value="Publish news"></p>
</form>
</body>
</html>


#new_post.php

<?php

header("Content-type;text/html;charset=utf-8");
$_POST['title'] = empty($_POST['title']) ? '' : $_POST[ 'title'];
$_POST['content'] = empty($_POST['content']) ? '' : $_POST['content'];
$title=$_POST['title' ];
$content=$_POST['content'];

$time=date("Y-m-d H:i:s");
$conn = mysqli_connect('localhost',' root','root','new','30');
mysqli_set_charset($conn,'utf8');
if($conn){
$sql="insert into news(title ,content,cre_time) VALUES('$title','$content','$time')";
$que=mysqli_query($conn,$sql);//Execute sql statement
if($ que){
                                              using using using using using   using   using     using ‐ ‐ que){
‐   ‐ ‐ echo "<script>alert('Published successfully, return to news list');location.href='new_list.php'</script>";  
   }else{
            die ("Database connection failed".mysqli_connect_error());
}

}###
TasselTassel2700 days ago1341

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-07-12 10:04:03

    The data cannot be inserted into the database. There are many situations. Is there any error message? If not, use breakpoint debugging to find the problem!

    reply
    0
  • 代言

    代言2017-07-11 17:10:35

    Print the $sql statement and observe.

    reply
    0
  • Cancelreply