doforumda Posted May 23, 2011 Share Posted May 23, 2011 Hi I am having this error while running my php script using ajax. Everything seems to be fine but I do not know why it is giving this error. <br /> <b>Notice</b>: Undefined index: amount in <b>C:\wamp\www\...\add_bid.php</b> on line <b>3</b><br /> {"error":"yes","fieldErrors":null} Here is my code here is .php code which contains the form <?php session_start(); $auctionid = $_POST['auction_id']; include "design/header.php"; include "DB/db.php"; ?> <div class="contents" id="bid_contents"> <?php $q = "SELECT * FROM bids WHERE productid='$auctionid' ORDER BY bidid DESC LIMIT 0,1"; $query = mysql_query($q) or mysql_error(); //echo $q; $row = mysql_fetch_assoc($query) or mysql_error(); $current_bid = $row['current_bid']; $thumbnail = mysql_query("SELECT * FROM products WHERE productid='$auctionid'"); $row_thumb = mysql_fetch_assoc($thumbnail); $thumb = $row_thumb['thumbnail']; $title = $row_thumb['product_title']; ?> <div id="thumb"> <img src='<?php echo $thumb ?>' border='none' /><br /> <?php echo $title."<br />"; echo "<b>Current Bid:</b> Eur ".$current_bid; ?> <form name="bid_form" id="bid_form"> <input type="text" name="amount" size="5" /> <input type="button" name="place_bid_btn" id="bid_btn" value="Place Bid" /> <div id="message"></div> </form> </div><!-- thumb --> </div> <?php include "design/footer.php" ?> here is .js file for ajax $(function() { $('#bid_btn').click(function() { var url = 'add_bid.php'; var query = $('#bid_form').serialize(); alert(query); $.ajax({ type: 'POST', url: url, query: query, dataType: 'json', success: function(data) { if(data.error == 'no') { $('#message').css('display','none'); } else { $('#message').html(data.fieldErrors).css('display','block'); } } }); }); }); and here is where i get data from previous .php file and the problem seems to be in this page. I guess. Name of this page is add_bid.php <?php session_start(); $bid = $_POST['amount']; $error = 'yes'; $msg = $bid; $JSON_array = array('error' => $error, 'fieldErrors' => $msg); $JSON_response = json_encode($JSON_array); header('Content-type: application/json'); echo $JSON_response; ?> I am adding jquery library and javascript file in my header.php file so it is fine. Please help Quote Link to comment https://forums.phpfreaks.com/topic/237202-need-help-with-post-method/ Share on other sites More sharing options...
Adam Posted May 23, 2011 Share Posted May 23, 2011 The error you're seeing is only a notice, telling you that $_POST['auction_id'] does not exist. You should always ensure you check variables/array keys exist, in situations where there's a chance they might not, with isset or empty - depending on what value you're expecting. Quote Link to comment https://forums.phpfreaks.com/topic/237202-need-help-with-post-method/#findComment-1219006 Share on other sites More sharing options...
doforumda Posted May 23, 2011 Author Share Posted May 23, 2011 The problem is at this line $bid = $_POST['amount']; I did this now if(isset($_POST['amount'])) { $msg = "amount is set"; } else { $msg = "Amount is not set"; } now it shows Amount is not set but I am sending data to this page but it says it is not set. Help Quote Link to comment https://forums.phpfreaks.com/topic/237202-need-help-with-post-method/#findComment-1219010 Share on other sites More sharing options...
PFMaBiSmAd Posted May 23, 2011 Share Posted May 23, 2011 AFAIK there's no query: parameter listed in the documentation for the .ajax function. I suspect you wanted to use data: Quote Link to comment https://forums.phpfreaks.com/topic/237202-need-help-with-post-method/#findComment-1219017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.