I want to make a form that sends a feedback (good/average/poor) in a mysql database without loading the page I'm on. It's working fine except that it doesn't recognize if wich value I'm sending (if it's good, average or poor that was sent).
Here my form :
<form method="post" id="radio_fb" style="margin-top:-90px;">
<p>
<input type="radio" name="radios" id="poor" value="poor" /><label for="poor">Poor</label>
<input type="radio" name="radios" id="average" value="average" checked="checked" /><label for="average">Average</label>
<input type="radio" name="radios" id="good" value="good" /><label for="good">Good</label>
<input type="hidden" name="url" value="<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];?> "/>
<input type="submit" name="submitter" value="Send" id="submit" />
</p>
</form>
And here is my jQuery :
jQuery(document).ready(function($) {
$("#radio_fb").submit(function() {
cname = this.radios.value;
curl = this.url.value;
submitter = this.submitter;
var data = {
name: cname,
url: curl
};
$.post("ajax.php", data, function() {
submitter.value="Sent";
submitter.disabled=true;
});
return false;
});
});
And here are the functions that store the value in the database:
<?php
include_once('config.php');
if ($_POST['radios'] == 'good') {
$url = $_POST['url'];
$bdd->exec('INSERT INTO feedback(id, url, avis) VALUES ("", "'. $url .'", "Good")');
} else if ($_POST['radios'] == 'average') {
$url = $_POST['url'];
$bdd->exec('INSERT INTO feedback(id, url, avis) VALUES ("", "'. $url .'", "Average")');
} else {
$url = $_POST['url'];
$bdd->exec('INSERT INTO feedback(id, url, avis) VALUES ("", "'. $url .'", "Poor")');
}
?>
Any idea how to fix this? I looked through all the answers but nothing is working: my function keeps returning the else statement (or nothing if I remove it).