Jump to content

funbinod

Members
  • Content Count

    499
  • Joined

  • Last visited

Posts posted by funbinod

  1. Why do you specify the enctype, is that necessary with jQuery? What about the other properties you're sending to the ajax method, do you know what all of those do and that you have them set correctly?

     

    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

  2. Can you show html form and how the ajax is triggered.

    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".

  3. Where is the value for $img coming from?

     

    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.

  4. AND WHAT! is the 'process.php' using to read ajax data sent to it? $_POST, $_GET, or $_REQUEST.

     

    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>';
    		}
            }
    
  5. 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.

  6.  

    Try adding $stmt->store_result(); after $stmt->bind_result()

    
    
    
    

     

    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...

     

     

    :)

  7. 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...

  8. @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?

  9. 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.

     

     

×
×
  • Create New...