Jump to content

funbinod

Members
  • Content Count

    499
  • Joined

  • Last visited

Everything posted by funbinod

  1. thank u. last one: does this upload file??
  2. i tried "$.post" in stead of "$.ajax" and the form is sent to target properly. but i faced another problem with file upload. the response from php says "$_FILES['img']" to be undefined index.
  3. because i'm uploading image also. so i thought i need to specify this, as i need this as i need in html form. and i read the same on some tutorials about sending image using ajax
  4. here is the html form <form id="pgm" name="pgm" method="post"> <input type="file" id="m" name="m" value="pgmadd" hidden="hidden" /> <span>Program:</span> <span><input type="text" id="head" name="head" placeholder="Name of Program" /></span><br /><br /> <span>Image:</span> <span><input type="file" id="img" name="img" /></span><br /><hr /> <span>Description:</span> <span><textarea rows="10" id="description" name="description" placeholder="Description of Program"></textarea></span><br /><br /> <input id="submit" name="submit" value="Submit" type="submit" /> </form> and here is the ajax request <script> $(document).ready(function(e) { function submIt() { $('input').attr('disabled', 'disabled'); $.ajax({ url:"process.php", dataType:"text", processData:false, contentType:false, enctype:"multipart/form-data", type:'POST', data: { m: 'pgmadd', hdng: $('#head').val(), img: $('#img').val(), description: $('#description').val() }, success: function(result) { $('input').removeAttr('disabled'); if ($(result).filter('#success').text() == '' || $(result).filter('#success').text() == 'NO'){ $('input, textarea').css('border', '2px solid red'); alert('return but error!'); alert($(result).filter('#msg').text()); } else { $('input').removeAttr('disabled'); $('input, textarea').css('border', '1px solid green'); alert('return success'); alert($(result).filter('#msg').text()); $('#adit').empty(); $('#adit').load('pgmadd.php'); } }, error: function() { $('input').removeAttr('disabled'); $('input, textarea').css('border', '2px solid red'); alert('error with error'); alert($(result).filter('#msg').text()); } }); } $('#submit').on('click', function(e) { submIt(); }); }) </script> i again remind. this is working properly when i use "type: GET".
  5. i thought if it would work if i use newer version. it was (and still is) the same while using 1.8.2
  6. there is nothing in the response. what it displays is the only message from the php when it is not called from proper $_POST['m'].
  7. in the network tab of developer tool, it says the status is 200 (i.e. ok) but i found that the ajax is not sending any data to the php (or php is not receiving the data from ajax).
  8. anybody here? i'm still stuck in this problem.. please help!
  9. its from rest of the code that is used to upload the image. its like: $img = $dir . basename($_FILES["img"]["name"]); edit: and the "$dir" depends on the value according to the value of "$m". its also defined above on the rest of the code.
  10. its obviously $_POST here is the PHP $m = $_POST['m']; if ($m == 'pgmadd') { $head = ($_POST['hdng']); $descr = ($_POST['description']); $usenow = 'Y'; $sql = $mysqli->prepare("INSERT INTO programs (head, description, status, filepath) VALUES(?,?,?,?)"); if (!$sql) { echo '<div id="success">NO</div>'; echo '<div id="msg">Error: '.$mysqli->error.'</div>'; } else { $sql->bind_param('ssss', $head, $descr, $usenow, $img); $msg = "Added Successfully!"; } if ($sql->execute()) { echo '<div id="success">YES</div>'; echo '<div id="msg">'.$msg.'</div>'; } else { echo '<div id="success">NO</div>'; echo '<div id="msg">Error: '.$mysqli->error.'</div>'; } }
  11. the w3c validator says there are 71 errors in your page. one of them is in line 213. style="font-size: 14px; "margin-left: 25px; margin-right: 25px;" here is the closing double inverted comma (") in between the style attribute. try deleting this. and correct all other errors pointed by w3c validator.
  12. hello all. i got confused in sending form data using ajax. when i send data using ajax with GET type, it works fine. but when i send it with POST type it doesn't work here is the ajax i use : $(document).ready(function(e) { function submIt() { $('input').attr('disabled', 'disabled'); var formData = new FormData(document.getElementById("pgm")); $.ajax({ url:"process.php", dataType:"text", processData:false, contentType:false, enctype:"multipart/form-data", type:'POST', data: formData, success: function(result) { $('input').removeAttr('disabled'); if ($(result).filter('#success').text() == '' || $(result).filter('#success').text() == 'NO'){ $('input, textarea').css('border', '2px solid red'); alert($(result).filter('#msg').text()); } else { $('input').removeAttr('disabled'); $('input, textarea').css('border', '1px solid green'); alert($(result).filter('#msg').text()); $('#adit').empty(); $('#adit').load('pgmadd.php'); } }, error: function() { $('input').removeAttr('disabled'); $('input, textarea').css('border', '2px solid red'); alert($(result).filter('#msg').text()); } }); } $('#submit').on('click', function(e) { if ($('#head').val() == '' || $('#desc').val() == '') { if ($('#head').val() == '') { alert('Program name is blank!'); $('#head').select(); $('#head').css('border', '2px solid red'); } if ($('#desc').val() == '') { alert('Description is empty!'); $('#desc').css('border', '2px solid red'); $('#head').select(); } } else { submIt(); } }); }) it is working properly when i use < type: 'GET' > Edit: I'm using jQuery 1.8.2 please guide me. thanks in advance.
  13. i found out that its not by adding $stmt->store_result() AFTER bind_result(). but its solved by adding $stmt->store_result() BEFORE bind result. somewhere on the web i read that when selecting a longtext() field, we have to use store_result before bind_result. and now the problem is solved. thank u all for being with me to solve this problem...
  14. getting more interesting.. it works fine for all columns when i use simple "$mysqli->query". but when i use prepared statement, it doesn't work for the column - description, even selecting only that coulmn
  15. it echoed 1 and 2. this means it stopped while binding result??
  16. its still not working using backticks `description`. what could be the possible reason for not working?? its worrying me... edit: the column's type is set to longtext()... edit: i even tried changing the column's name... still no improve...
  17. @Don E ---------------- the problem is only that it doesn't work when i select 'description' column. otherwise it works fine. using the column even doesn't show any error. it just doesn't work without showing any error. i even tried getting error, if any, on execute (i.e., if(!$stmt->execute()) {echo $mysqli->error;} ) but it didn't show any error msg. ========================== is 'description' a reserved word?
  18. yes! nothing is returning false.
  19. hello all! i was writing a mysql prepared statement on php and i stuck at one point that made me feel something interesting. the following query works fine only after i remove the column 'description'. but selecting the column doesn't work and shows no error. if($stmt = $mysqli->prepare("SELECT item,sid,catid,oqty,unitid,sprice,pprice,description FROM stock WHERE (icode=? or bcode=?) AND cid=?")) { $stmt->bind_param('ssi', $icode, $icode, $cid); $stmt->execute(); $stmt->bind_result($item,$sid,$catid,$oqty,$unitid,$sprice,$pprice,$description); $stmt->fetch(); $stmt->close(); $stmt->free_result(); } else { echo 'Error: '.$mysqli->error; } and yes! these is existence of column named 'description'. i'm stuck at this point. please guide me why is this happening.
  20. yes but, i thought, there could be some special method to send SAME DATA to multiple pages using single ajax request in stead of writing multiple ajax requests for SAME DATA. is there any special method??
  21. hello all! greetings! i'm learning jquery ajax. i understood how we send data to another page and get result from there. but i'm thinking if i can send same data to multiple pages or not. please guide.
  22. uhhhh! thank u! it worked. actually i'm new to jquery ajax and i don't know every part of this. thank u for guiding me to this.
×
×
  • Create New...