I'm triyng to pass a var value from javaScript to php and i'm getting this error Undefined index: postmarca in C: . The objective was to avoid php returning the value of marcaID, which is the primary key and return the selection name defined as "marca", which is obtained from a DB
What am i doing wrong?
<?php
$marca = $_POST['postmarca'];
echo "$marca";
?>
<html>
<head>
<script type= "text/javascript" src="jquery-3.1.1.min.js"></script>
</head>
<body>
<div id="reg">
<form>
<select name="marca" class="marca" id="marca">
<option selected="selected">--Select MArca--</option>
<?php
$stmt = $db->prepare("SELECT * FROM tabl_marca");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<option value="<?php echo $row['marcaID']; ?>">
<?php echo $row['marcas']; ?></option>
<?php
}
?>
</select>
<input type="button" value="submit" onclick="post();">
</form>
</div>
</body>
JAVASCRIPT
<script type= "text/javascript">
function submit()
{
var marca= $('#marca').val();
$.post('tester.php', {postmarca:marca}, function(data)
{
$('#reg').html(data);
});
}
</script>