사용자 이름과 암호를 가져와 데이터베이스에 등록하는 간단한 html 양식이 있습니다. 그러나 폼이 제출되기 전에 페이지가로드되는 즉시 한 번 다음 php if 문을 실행합니다. 다음은 그 코드입니다.양식 제출 전에 실행중인 자바 스크립트
if (($_POST['reg_username']=="") || ($_POST['reg_password']==""))
{ ?>
<script> alert("please enter both email and password"); </script>
<? }
전체 PHP 코드가 아래에 있습니다. 이것은 최종 코드가 아니기 때문에 여전히 암호와 모든 것을 암호화하지 않았지만 그냥 테스트하고 있습니다. 선배 들께 감사드립니다.
if (($_POST['reg_username']=="") || ($_POST['reg_password']==""))
{ ?>
<script> alert("please enter both email and password"); </script>
<? }
$reg_username=mysql_real_escape_string($_POST['reg_username']);
$reg_username=htmlspecialchars($reg_username);
$reg_password=mysql_real_escape_string($_POST['reg_password']);
$reg_password=htmlspecialchars($reg_password);
if(!empty($reg_username) && !empty($reg_password))
{
if (isset($reg_username) && isset($reg_password))
{
mysql_select_db($db, $dbconnect);
mysql_query("INSERT into students(username,password) VALUES
('$reg_username','$reg_password')");
}
}
?>
가능한 중복 [다시 변경하기 ference : 왜 내 자바 스크립트에서 PHP (또는 다른 서버 측) 코드가 작동하지 않습니까?] (http://stackoverflow.com/questions/13840429/reference-why-does-the-php-or-other-server-side -code-in-my-javascript-not-wor) – Quentin