2016-11-01 11 views
0

これは私のHTML形式です。フォームの作成中にPOSTメソッドエラーが発生しましたか?

<html> 
<head> 
</head> 
<body> 
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> 
<tr> 
<form id="form" name="form" method="POST" action="add_new_topic.php"> 
<td> 
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> 
<tr> 
<td colspan="3" bgcolor="#E6E6E6"><strong>Create New Topic</strong> </td> 
</tr> 
<tr> 
<td width="14%"><strong>Topic</strong></td> 
<td width="2%">:</td> 
<td width="84%"><input name="topic" type="text" id="topic" size="50" /></td> 
</tr> 
<tr> 
<td valign="top"><strong>Detail</strong></td> 
<td valign="top">:</td> 
<td><textarea name="detail" cols="50" rows="3" id="detail"></textarea></td> 
</tr> 
<tr> 
<td><strong>Name</strong></td> 
<td>:</td> 
<td><input name="name" type="text" id="name" size="50" /></td> 
</tr> 
<tr> 
<td><strong>Email</strong></td> 
<td>:</td> 
<td><input name="email" type="text" id="email" size="50" /></td> 
</tr> 
<tr> 
<td>&nbsp;</td> 
<td>&nbsp;</td> 
<td><input type="submit" name="Submit" value="Submit" /> 
<input type="reset" name="Submit2" value="Reset" /></td> 
</tr> 
</table> 
</td> 
</form> 
</tr> 
</table> 
</body> 
</html> 

これはadd_new_topic.phpコードです。

<?php 

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="myforum"; // Database name 
$tbl_name="fquestions"; // Table name 

// Connect to server and select database. 
$con = mysqli_connect("$host", "$username", "$password" , "$db_name"); 
if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 
mysqli_select_db($con,"$db_name")or die("cannot select DB"); 

// get data that sent from form 
$topic=$_POST['topic']; 
$detail=$_POST['detail']; 
$name=$_POST['name']; 
$email=$_POST['email']; 

$datetime=date("d/m/y h:i:s"); //create date time 

$sql="INSERT INTO '$tbl_name'('topic',' detail', 'name', 'email', 'datetime')VALUES('topic', 'detail', 'name', 'email', 'datetime')"; 
$result=mysqli_query($con,$sql); 

if($result){ 
echo "Successful<BR>"; 
echo "<a href=main_forum.php>View your topic</a>"; 
} 
else { 
echo "ERROR"; 
} 
mysqli_close($con); 
?> 

それがエラーを示しています

お知らせ:未定義のインデックス: Cのトピック:ライン上の\ xamppの\ htdocsに\ myforum \ add_new_topic.php 18

お知らせ:未定義のインデックス: Cで詳細:\ xamppの\ htdocsに\ myforum \ add_new_topic.phpライン上の19

お知らせ:未定義のインデックス: Cでの名前:\ xamppの\ htdocsに\ myforum \ add_new_topicライン上の.php 20

お知らせ:未定義のインデックス: Cでの電子メール:ライン上の\ xamppの\ htdocsに\ myforum \ add_new_topic.php 21 ERRORライン18,19上HERE


、図20と21には、次のコードがあります。

$topic=$_POST['topic']; 
$detail=$_POST['detail']; 
$name=$_POST['name']; 
$email=$_POST['email']; 

このPOSTメソッドのエラーは何ですか?ポストの値は、次のように空にされていない場合は、ポストの値は条件を追加取得する前に

+0

使用 'ISSETを()'メソッドはまた、あなたはSQLインジェクションに開いているクエリ – Karthi

+1

で '$'を欠場します。変数にクエリを渡すことはありません。あなたのクエリはテーブル/カラムの引用符を使用しています。 'd/m/y h:i:s'はmysql datetime形式ではありません。 'mysqli_select_db'は、接続にすでに割り当てているので、必要ありません。何故エラーが出るのかという疑問に対して、 '$ _POST'には何が入っていますか? HTMLフォームは 'add_new_topic.php'にありますか? – chris85

答えて

1

<?php 

    $host="localhost"; // Host name 
    $username="root"; // Mysql username 
    $password=""; // Mysql password 
    $db_name="myforum"; // Database name 
    $tbl_name="fquestions"; // Table name 

    if(isset($_POST) && !empty($_POST)){ 
    // Connect to server and select database. 
    $con = mysqli_connect("$host", "$username", "$password" , "$db_name"); 
    if (mysqli_connect_errno()) 
     { 
     echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
     } 
    mysqli_select_db($con,"$db_name")or die("cannot select DB"); 

    // get data that sent from form 
    $topic=$_POST['topic']; 
    $detail=$_POST['detail']; 
    $name=$_POST['name']; 
    $email=$_POST['email']; 

    $datetime=date("d/m/y h:i:s"); //create date time 

    $sql="INSERT INTO '$tbl_name'('topic',' detail', 'name', 'email', 'datetime')VALUES('$topic', '$detail', '$name', '$email', '$datetime')"; 

    if($result){ 
    echo "Successful<BR>"; 
    echo "<a href=main_forum.php>View your topic</a>"; 
    } 
    else { 
    echo "ERROR"; 
    } 
    mysqli_close($con); 
    } 
    ?> 
+1

引用符 '$ topic' ........などを逃す – Karthi

+0

私は間違いを犯したことを言及してください? –

+1

あなたの 'クエリの値を挿入する( '')'引用符がありません – Karthi

関連する問題