Data tidak boleh dimasukkan ke dalam pangkalan data
Tassel
Tassel 2017-07-11 12:49:55
0
2
1339

form.html

<!DOCTYPE html>
<html lang="ms">
<head>
<meta charset="UTF-8">
<tajuk> Tajuk</tajuk>
<gaya>
badan{
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
     </script>
< /head>
<body>
<form method="post" action= "new_post.php" name="myform" onsubmit="return foo();">
<h1>Ini ialah sistem berita< ;/h1>
<p>Tajuk:<input type="text" name="title"></p>
<p>Content:<textarea cols="30" rows="5 " name="content"></textarea></p>
<p><input type="submit" value="Terbitkan Berita"></p>
</form>
</body>
</html>





new_post .php


<?php

header("Content-type;text/html;charset=utf-8");
$_POST['title'] = kosong($_POST['title']) ? ;
$_POST['kandungan'] = kosong($_POST['kandungan']) ? '' : $_POST['kandungan'];
$tajuk=$_POST['tajuk'];
$kandungan=$_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); // Laksanakan pernyataan sql
if($que){
echo "<skrip>alert('Berjaya diterbitkan, kembali ke senarai berita');location.href = 'new_list.php'</script>";
}else{
 die("Sambungan pangkalan data gagal".mysqli_connect_error());
}
}

Tassel
Tassel

membalas semua(2)
ringa_lee

Data tidak boleh dimasukkan ke dalam pangkalan data Terdapat banyak situasi. Adakah terdapat sebarang mesej ralat.

代言

Cetak penyata $sql dan amati.

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan