我有這個代碼,我想現在要做的就是一旦我點擊一個href =「submitreserve.php」>保留<所有行中的值將會被選中保存到$ _POST,以便我可以在我的submitreserve.php代碼中獲取它們。如何獲取表格中的一行中的值php
echo'<table>
<tr>
<th> ID. </th>
<th> Year Level </th>
<th> Course </th>
<th> Description </th>
<th> Action </th>
</tr>
<tr>';
$con = mysql_connect("localhost","root","");
if(!$con){
die('Could not connect to database' .mysql_error());
}
else{
mysql_select_db("enrollment", $con);
}
$result = mysql_query("SELECT * FROM tblsubjectoffer where course = '$course' and semester = '$sem' and year = '$year'");
if(!$result){
die('Invalid query:' .mysql_error());
}
else{
while($row = mysql_fetch_array($result))
{
echo'<td class="offerCell">'.$row['offer'].'</td>';
echo'<td class="yearCell">'.$row['year'].'</td>';
echo'<td class="courseCell">'.$row['course'].'</td>';
echo'<td class="descCell">'.$row['sub_desc'].'</td>';
echo'<td><a href="submitreserve.php" class="insertButton">Reserve</a></td>';
echo'</tr>';
}
}
}
echo'</table>';
?>
我的submit.php代碼必須是這樣的。
$id = $_POST['id'];
$year = $_POST['year'];
$course = $_POST['course'];
$desc = $_POST['description'];
$sql=mysql_query("insert into tbldepartment (id, year, course, description) values('$id','$year','$course','$desc')");
這樣的事情。任何人都可以幫助我?我堅持了近2周。請幫幫我。
不要忘了清理您的數據。我建議切換到'mysqli',然後使用'$ year = mysqli_escape_string($ con,$ _POST ['year'];'等等 – rybo111