我知道动作未定义,但我不知道如何修复它。
这是我的代码,我尝试使用一个表来添加,删除和更新所选行。添加工作,但更新和删除我有动作未定义的问题。
<script>
function changeRecord()
{
document.myForm.action='change.php';
document.myForm.submit();
}
function deleteRecord()
{
document.myForm.action='delete.php';
document.myForm.submit();
}
</script>
<?php
$servername = "localhost";
$username = "n00832038";
$password = "Fall2015832038";
$db = "n00832038";
$conn = mysqli_connect($servername, $username, $password, $db);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$query = "SELECT * FROM movies ";
$results = mysqli_query($conn, $query);
?>
</head>
<body>
<form action="add.php" method="get">
<table>
<tr>
<td>Movie Title: </td><td><input type='text' name='title'></td>
</tr>
<tr>
<td>Release Type: </td><td><select name='type'>
<option value="theaters">Theaters</option>
<option value="direct">Direct to Video</option>
<option value="television">T.V.</option>
</select>
</td>
</tr>
<tr>
<td>Release Year: </td><td><input type='text' name='year'></td>
</tr>
<tr>
<td>Remake: </td><td><input type='radio' name='remake' value='yes'> Yes</td>
<td><input type='radio' name='remake' value='no'> No</td>
</tr>
<tr>
<td>Based On A Book: </td><td><input type='radio' name='basedbook' value='yes'> Yes</td>
<td><input type='radio' name='basedbook' value='no'> No</td>
</tr>
<tr> <td colspan='2'> <input type='submit' value='Add Record'></td>
</table>
<form action='' name='myForm' method= 'get'>
<?php
echo "<table border='1'>";
while($row = mysqli_fetch_row($results))
{
$MoviesID = $row[0];
$Title = $row[1];
$ReleaseType = $row[2];
$ReleaseYear = $row[3];
$Remake = $row[4];
$BasedonBook = $row[5];
echo "<tr>";
echo "<td><input type='radio' name='movieID' value='$MoviesID'></td>";
echo "<td>$Title</td>";
echo "<td>$ReleaseType</td>";
echo "<td>$ReleaseYear</td>";
echo "<td>$Remake</td>";
echo "<td>$BasedonBook</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
<input type='button' value='Delete Record' onClick='deleteRecord()'>
<input type='button' value='Update Record' onClick='changeRecord()'>
</form>
</body>
答案 0 :(得分:1)
您应该进行以下更改:
JS:
function changeRecord()
{
document.getElementById("myForm").action='change.php';
document.getElementById("myForm").submit();
}
function deleteRecord()
{
document.getElementById("myForm").action='delete.php';
document.getElementById("myForm").submit();
}
和HTML:
<form action="add.php" method="get" id="myForm">