Data cannot be inserted into the database
Tassel
Tassel 2017-07-11 12:49:55
0
2
1340

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());
}

}###
Tassel
Tassel

reply all(2)
ringa_lee

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!

代言

Print the $sql statement and observe.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template