나는이 코드를 가지고 있으며, 지금은 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 주 동안 이것에 갇혀있다. 도와주세요.
<a href="submitreserve.php" onclick="reserve(val1, val2, val3, val4)">Reserve</a>
는 PHP 코드는 예비 함수 호출의 매개 변수를 넣어 유무 :
데이터를 소독하는 것을 잊지 마십시오. mysqli로 전환 한 다음 $ year = mysqli_escape_string ($ con, $ _POST [ 'year']; 등)을 사용하는 것이 좋습니다. – rybo111