I'm trying to make an page where you can select a value in a dropdown select box. When the selection is made it should update the database using the selected value. I use 2 pages one including the html/javascript and one using php. Currently when i select something nothing happens.
What am i doing wrong?
test.php
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script>
function updateDb() {
$.post("buh.php", $("#form").serialize());
}
</script>
</head>
<body>
<form id="form">
<?php
include 'Includes/database_connection.php';
$sql = "select * FROM sims ORDER BY phonenr asc" ;
$result = mysql_query($sql,$con);
echo "<select id='select' name='select' onChange='updateDb()'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['phonenr'] . "'>" . $row['phonenr'] . "</option>";
}
echo "</select>";
?>
</form>
</body>
And buh.php
<?php
include 'Includes/database_connection.php';
$sql = "select * FROM sims ORDER WHERE phonenr='".mysql_escape_string($_POST["select"])."'" ;
$result = mysql_query($sql,$con);
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
mysql_query("UPDATE pairings SET sim_id='$id' WHERE unit_id='1'")
or die(mysql_error());
}
?>