开发者

jQuery .serialize not posting to PHP.. or is it the PHP?

Related to my question yesterday: My two radio buttons that will change prices on change:

<form id="f-p" method="post" action="forms.php">
         <label for="exkl">Exkl. moms</label>
         <input name="moms" id="exkl" type="radio" value="exkl" checked="checked" onClick="javascript:thisWorks();"/>
         <label for="inkl">Inkl. moms</label>
         <input name="moms" id="inkl" type="radio" value="" onClick="javascript:thisWorks();"/>
  </form>

I intend to use this PHP:

if ($_POST["moms"] = "exkl") {
   echo "Nothing.";
 } else if($_POST["moms"] = "inkl") {
$inkl_query ="SELECT `product_id` FROM `cms_module_products_fieldvals` WHERE `fielddef_id`=4"开发者_开发知识库;
$iresult = mysql_query($inkl_query);
while ($row = mysql_fetch_row($iresult)) {
   var_dump($row);
   $inkVal = $row->value;
   echo $InkVal;
 }
} 

with this jQuery to post the value:

function thisWorks() {
$.ajax({
    data: $('form#f-p').serialize() + "&formSubmit=true",
    type: "POST",
    url:"forms.php", 
    success: function() {
            tar = $('form#f-p').serialize();
            alert(tar);
        }
    });
}
$('input[name=moms]').change(thisWorks);
thisWorks();

Now, I am getting the alerts from the Jquery with the posted values, so they are working there. It will either say "moms=inkl" or "moms=exkl". (Don't know whether that is the problem. But they are not working in the PHP. I do not get the mySQL Query. The page loads and any value change doesn't produce any change in how PHP handles the form. What's going on?


Here's a problem:

if ($_POST["moms"] = "exkl") {
   echo "Nothing.";
 } else if($_POST["moms"] = "inkl") {

Your if statement is always true, because $_POST["moms"] = "exkl" isn't checking equality. It' just sets $_POST["moms"] equal to "exkl". Same goes for the else if.

Change this code:

if ($_POST["moms"] = "exkl") {
   echo "Nothing.";
 } else if($_POST["moms"] = "inkl") {

To this code:

if ($_POST["moms"] == "exkl") {
   echo "Nothing.";
 } else if($_POST["moms"] == "inkl") {

And see what happens.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜