그래서, 나는 다음과 같은 코드를 가지고 :이 PHP를 양식으로 이동 그래서삽입 검증 Foreach 루프 문제
$required = array('uexam_id', 'usubject', 'uexam_date');
$error = false;
//VALIDATION: first check all required fields are not empty. if post has values
if(!empty($_POST))
foreach($required as $field)
if (empty($_POST[$field]))
$error = true;
//a field was empty, show error
if ($error) {
die ("All fields required!!! <a href='examisud.php'> Back to PHP Form </a>");
}
//no error - try the query
elseif($error === false && !empty($_POST))
{
$InsertQuery = "INSERT INTO Exam (exam_id, subject, exam_date) VALUES ('$_POST[uexam_id]','$_POST[usubject]','$_POST[uexam_date]')";
$result = mysql_query($InsertQuery, $con) or die('query Failure:'. mysql_error());
}
을 (지금은 SQL 주입/MySQL의 감가 상각에 대해 걱정하지 마십시오)을 (examisud.php) , 나는 "모든 분야가 필요함"으로 처음으로 인사합니다. 그런 다음 양식으로 돌아가서 모든 필드가 채워져 있지 않으면 정상적인 데이터 삽입 및 오류 표시로 작동합니다. * 양식 페이지로드시 "모든 필드 필요"가 표시되지 않도록하려면 어떻게해야합니까? 나는 그것을 필요로한다 (들판이 비어있을 때). 또한 필드를 업데이트하거나 삭제할 때 "모든 필드가 필요합니다"라는 오류 메시지가 나타납니다. 그러나 모든 것이 업데이트/정상적인 오류를 제외하고 삭제 가져옵니다.
그래서 기본적으로 필드가 삽입 쿼리에 공백으로 남을 때 표시해야합니다. 도움을 주시면 미리 감사드립니다. 양식 제출 여부를 확인해야합니다 여부를
예를 들어이
<input type="submit" name="submit">
then in your php check it like this
if(!empty($_POST['submit']))//means the form is submitted
{
//your code
}
else
{
//no form is submitted here display your form normally
?>
<form action="" method="POST">
......
......
<input type="submit" name="submit">
</form>
<?php
}
이 도움이 되었으면 좋겠 같은 형태로 제출하는 경우
{
echo "<form action=examisud.php method=post>"; //HTML FORM ECHOED OUT BY PHP
echo "<tr>";
echo "<td>" . "<input type=text name=exam_id value=" . $record['exam_id'] . " </td>";
echo "<td>" . "<input type=text name=subject value=" . $record['subject'] . " </td>";
echo "<td>" . "<input type=text name=exam_date value=" . $record['exam_date'] . " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $record['exam_id'] . " </td>";
echo "<td>" . "<input type=image name=update value=update id=submit src=images/update.png" . " </td>";
echo "<td>" . "<input type=image name=delete value=delete id=submit src=images/delete.png" . " </td>";
echo "</tr>";
echo "</form>";
}
echo "<form action=examisud.php method=post>";
echo "<tr>";
echo "<td><input type=text name=uexam_id></td>";
echo "<td><input type=text name=usubject></td>";
echo "<td><input type=text name=uexam_date></td>";
echo "<td>" . "<input type=image name=insert value=insert id=submit src=images/insert.png" . " </td>";
echo "</form>";
echo "</table>";
양식에 숨겨진 필드를 넣고 코드에 숨겨진 변수가 있는지 확인하십시오. 양식이있는 경우 양식이 제출됩니다. 그렇지 않은 경우 "처음 방문" –
'SQL 주입에 대해 걱정하지 마십시오./mysql depreciation for now' : 걱정할 필요가있는 사람이 아닙니다 * * do :) –