みんな、入力されたデータをデータベースに挿入できないようにしているこのコードの問題を誰かが見つけてくれることを願っています。
ここで同様のスレッドを見たことがあります。1 つまたは 2 つのことを修正しましたが、まだ機能していないようです。そのため、この投稿を作成しました。
また、フォーム フィールド/変数が 3 つしかない場合でも、このコードは問題なく動作しました。さらにいくつか作成したので、送信された値はデータベースに送信されません。
誰かが尋ねた場合、同じページに結果を表示する機能は正常に機能しています。データベースに手動で値を挿入しようとしたところ、ファイルに表示されたので、問題は実際には挿入機能にあると思いました。 .
なぜそれがうまくいかないのか、誰かが私を助けることができますか?
<?php
mysql_connect("localhost","root","");
mysql_select_db("activitytest1");
if(isset($_POST['type'])) { $type = $_POST['type']; }
if(isset($_POST['description'])){ $description = $_POST['description']; }
if(isset($_POST['author'])) { $author = $_POST['author']; }
if(isset($_POST['pre'])) { $pre = $_POST['pre']; }
if(isset($_POST['while'])) { $while = $_POST['while']; }
if(isset($_POST['postact'])) { $postact = $_POST['postact']; }
if(isset($_POST['outcome'])) { $outcome = $_POST['outcome']; }
if(isset($_POST['path'])) { $path = $_POST['path']; }
if(isset($_POST['books'])) { $books = $_POST['books']; }
if(isset($_POST['grouping'])) { $grouping = $_POST['grouping']; }
if(isset($_POST['time'])) { $time = $_POST['time']; }
if(isset($_POST['submit'])) { $submit = $_POST['submit']; }
$dbLink = mysql_connect("localhost", "root", "");
mysql_query("SET character_set_client=utf8", $dbLink);
mysql_query("SET character_set_connection=utf8", $dbLink);
if (!empty($_POST['submit']))
{
if($type&&$description&&$author&&$pre&&$while&&$postact&&$outcome&&$path&&$books&&$grouping&&$time) {
$insert=mysql_query("INSERT INTO activitytest1 (type, description, author, pre, while, postact, outcome, path, books, grouping, time) VALUES ('".$_POST['type']."','".$_POST['description']."','".$_POST['author']."','".$_POST['pre']."', '".$_POST['while']."','".$_POST['postact']."','".$_POST['outcome']."','".$_POST['path']."', '".$_POST['books']."','".$_POST['grouping']."','".$_POST['time']."',)");
} else {
die ("Failed to connect to mysql: " . mysql_error());
}
}
$dbLink = mysql_connect("localhost", "root", "");
mysql_query("SET character_set_results=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF-8');
$getquery=mysql_query("SELECT * FROM activitytest1");
while($rows=mysql_fetch_assoc($getquery))
{
$type=$rows['type'];
$description=$rows['description'];
$author=$rows['author'];
$pre=$rows['pre'];
$while=$rows['while'];
$postact=$rows['postact'];
$outcome=$rows['outcome'];
$path=$rows['path'];
$books=$rows['books'];
$grouping=$rows['grouping'];
$time=$rows['time'];
echo '<br/>
<table width="909" border="1" align="center" cellpadding="5" cellspacing="0">
<tr>
<td width="125">' . $type . '</th>
<td width="680">' . $description . '</th>
<td width="120">' . $author . '</th>
</tr></table> <br/>' . $pre . '<br/>' . $while. '<br/>' . $postact . '<br/>' . $outcome . '<br/>' . $path . '<br/>' . $books . '<br/>' . $grouping . '<br/>' . $time . '
<hr size="1"/> ' ;}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test 1</title>
</head>
<body>
<br>
<table width="909" border="1" align="center" cellpadding="5" cellspacing="0">
<tr>
<th width="125" scope="col">Type</th>
<th width="680" scope="col">Description</th>
<th width="120" scope="col">Author</th>
</tr></table>
<br>
<form action="index.php" method="POST">
<table width="909" border="1" align="center" cellpadding="5" cellspacing="0">
<td width="125"><label>
</label>
<select name="type" id="type" onChange="display(this,'Task','Semi-task','Practice','Exercise','Lead-in');">
<option value="Unselected" selected="selected">Choose one:</option>
<option value="Task">Task</option>
<option value="Semi-task">Semi-task</option>
<option value="Practice">Practice</option>
<option value="Exercise">Exercise</option>
<option value="Lead-in">Lead-in</option>
<option value="Game">Game</option>
<option value="Video">Video</option>
<option value="Song">Song</option>
<option value="Mimio">Mimio</option>
<option value="Other">Other</option>
</select></td>
<td width="680"><div id="Semi-task" style="display: none;">
Pre:<br>
</div>
<div id="Exercise" style="display: none;">While:</div>
<br>
<div id="Practice" style="display: none;">
Post:<br>
<br>
</div>
<div id="Task" style="display: none;"> Outcome: <br />
<textarea name="description" cols="70" rows="2"></textarea>
<br />
</div>
<div id="Lead-in" style="display: none;">
Link/Path:<br>
<br>
</div></td>
<td width="120"><input name="author" type="text" size="12" maxlength="25" /></td>
</tr>
<tr>
<td colspan="3"> <textarea name="pre" id="Pre" cols="45" rows="5"></textarea>
<br /><textarea name="while" id="While" cols="45" rows="5"></textarea>
<br /><textarea name="postact" id="Post" cols="45" rows="5"></textarea>
<br /><textarea name="outcome" id="Outcome" cols="45" rows="5"></textarea>
<br /><input type="text" name="path" id="Path" />
<br /><input type="text" name="books" id="Books" />
<br /><input type="text" name="grouping" id="Grouping" />
<br /><input type="text" name="time" id="Time" />
</td>
</tr>
<tr>
<td colspan="3"><input type="submit" name="submit" value="Comment" /></td>
</tr>
</table>
</form>
</body>
</html>
親切にしてください、みんな、私はこれでまったくの初心者です。:)