球員,我希望有人可以幫助我找到這個代碼中的問題,以防止將輸入的數據插入到數據庫中。表格不會在數據庫中插入輸入的數據,但不會顯示任何錯誤
我在這裏看到過類似的線程,我糾正了一兩件事情,但它似乎並沒有工作,這就是爲什麼我創建了這篇文章。此外,當代碼只有三個表單域/變量時,此代碼完美無缺地工作。現在我已經創建了幾個,它不會將任何提交的值發送到數據庫。
如果有人應該問,在同一頁面顯示結果的函數工作正常,因爲我試圖手動在數據庫中插入值,並在文件中顯示,導致我認爲問題是真的與插入功能。
任何人都可以幫我找到爲什麼不去?
<?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>
請大家好,夥計們,我是這個總的新手。 :)
請不要使用'mysql_ *'作爲折舊。相反,你應該使用'mysqli_ *'或'PDO'。 –