我正在使用ajax和jquery选择框发布脚本。
我的问题是价值ID。当我clik post,然后数据库表只显示id号。但我想发布is_kategorisi。我能做什么 ? 这是我的选择框:
<?php
include('db.php');
$is_kategorisi =$_POST['id'];
$query = "SELECT * FROM business_category";
$res = mysql_query($query);
?>
<select id="parent_category" name="sirket_kategorisi" accept-charset="UTF-8" />
<?php
echo "<option value=''>Şirket Kategoriniz</option>";
while($row = mysql_fetch_array($res))
{
echo "<option value='".$row['is_kategorisi']."'>".ucfirst($row['is_kategorisi'])."</option>";
}
?>
</select>
这是我发布的php代码:
<?php
include("includes/connect.php");
if(isset($_POST['submit'])){
$sirket_kategorisi = $_POST['sirket_kategorisi'];
$query ="INSERT INTO `users` (`sirket_kategorisi`) VALUES ('$sirket_kategorisi')";
$result = mysql_query($query) or die(mysql_error());
if($result){
echo("<center><h1>OK!</h1></center>");
}
else {
echo("<center><h1>Not OK!</h1></center>");
}
}
?>
ajax代码:
<script type="text/javascript">
$(document).ready(function()
{
$("#parent_category").change(function()
{
var category_id = $(this).val();
if(category_id != '')
{
$.ajax
({
type: "POST",
url: "get_child.php",
data: "category_id="+ category_id,
success: function(option)
{
$("#child_category").html(option);
}
});
}
else
{
$("#child_category").html("<option value=''>-- No category selected --</option>");
}
return false;
});
});
</script>
get_child.php
<?php
include('db.php');
?>
<?php
if(isset($_POST['category_id']) && $_POST['category_id'] != '')
{
$category_id = $_POST['category_id'];
$category_id = mysql_real_escape_string($category_id);
$query = "SELECT * FROM business_category_name where catg='".$category_id."'";
$res = mysql_query($query);
if(mysql_num_rows($res))
{
while($row = mysql_fetch_array($res))
{
echo "<option value='".$row['category_name']."'>".ucfirst($row['category_name'])."</option>";
}
}
}
?>