我有一个名为 waiting.php 的页面,该页面是开始辅导员和学生之间真实生活会话的门户。我有一个名为“name='submit”的提交按钮
我有一段代码调用提交按钮(isset),一旦发生这种情况,我希望 PDO 语句执行插入查询。但是我检查了 phpmyadmin 并没有插入任何内容。
我的代码是这样的:
f(isset($_POST['submit'])){
$query = $dbh->prepare("INSERT INTO counselors (counselorname) VALUES (:counselorname)");
$query->bindParam(':counselorname', $_POST['namedrop']);
$query->execute();
}
现在这是制作提交按钮和辅导员姓名下拉菜单的实际代码:
echo "<td>
<form method= 'post'>
</form><select name='namedrop'>
<option value=''>Counselor Name</option>
<option value='dmin-John'>Admin - John</option>
<option value='Admin-Christine'>Admin - Christine</option>
<option value='Admin-Dawne'>Admin - Dawne</option>
<option value='Counselor-Cherie'>Counselor - Cherie</option>
<option value='Counselor-Tootie'>Counselor - Tootie</option>
<option value='Counselor-Debbie'>Counselor - Debbi</option>
<option value='FrontDesk-Delores'>Front Desk - Delores</option>
<option value='FrontDesk-Kiana'>Front Desk - Kiana</option>
</select>
</form>";
echo "<td> <form action='counselor.php?id=" . $row['id'] . "' method='post' target='_new'>
<input type='submit' name='submit' value='Start Session'>
</form> </td>";
我是 PHP 新手,所以我的逻辑有点像那里,但我的语法和知道如何实现我的逻辑低于平均水平。
任何帮助将非常感激。
编辑 :
这就是页面的外观:
编辑2:
echo "<td>
<form action='counselor.php?id=" . $row['id'] . "' method='post' target='_new'>
<select name='namedrop'>
<option value=''>Counselor Name</option>
<option value='dmin-John'>Admin - John</option>
<option value='Admin-Christine'>Admin - Christine</option>
<option value='Admin-Dawne'>Admin - Dawne</option>
<option value='Counselor-Cherie'>Counselor - Cherie</option>
<option value='Counselor-Tootie'>Counselor - Tootie</option>
<option value='Counselor-Debbie'>Counselor - Debbi</option>
<option value='FrontDesk-Delores'>Front Desk - Delores</option>
<option value='FrontDesk-Kiana'>Front Desk - Kiana</option>
</select>
<td> <input type='submit' name='submit' value='Start Session'>
</form> </td>";
}
echo "</tr>";
echo "</table>";
if(isset($_POST['submit'])){
$query = $dbh->prepare("INSERT INTO counselors (id, counselorname) VALUES (:id, :counselorname)");
$query = $dbh->bindParam(':id', $row['id']);
$query->bindParam(':counselorname', $_POST['namedrop']);
$query->execute();
}