드롭 다운 메뉴에서 선택된 영역 이름을 PHP를 통해 MySQL에 전달하려고합니다. 자바 스크립트에서 이름을 가져 왔지만 자바 스크립트에서 PHP로 값을 저장할 수 없습니다. 내 코드는 다음과 같습니다.PHP를 통해 MySQL에 Javascript 변수 값 전달
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script>
function getIndex()
{
var x=document.getElementById("cmbArea").selectedIndex;
var y=document.getElementById("cmbArea").options
var z= y[x].text;
alert(z);
}
</script>
</head>
<body>
<form name ="form1" action="Demo1.php" method="post">
<select id="cmbArea" name="cmbArea">
<?php
include 'Connect.php';
$query = "SELECT varAreaName FROM tbArea" ;
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
echo '<option value="'.$row['varAreaName'].'">' . $row['varAreaName'] . '</option>';
}
?>
</select>
</form>
<input type="Button" onclick="getIndex()" value="Alert index of selected option">
</body>
</html>
이것은 PHP에 데이터를 게시하는 양식 (및 선택 항목)을 만드는 HTML/PHP입니다. $ _POST를받는 다른 쪽을 볼 필요가 있습니다 – Popnoodles
서버에서 값을 읽으려면 양식을 제출해야합니다. –
mysql_ * 함수를 더 이상 사용하지 마십시오. 더 이상 사용되지 않습니다 ([red box] (http://php.net/mysql_query) 참조). 게다가'Demo1.php'를 보여줄 수 있습니까? –