-1

im having problem getting the output of php script passing it to html inputs

this is my php script

$stmt->execute(); 
    if ($stmt->rowCount() > 0){
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        echo 'Found: ' . $row['doctitle'] . ' ' . $row['doctype'];
    }else {
        echo "error";
    }

and this is my ajax

$.ajax({
            type: "POST",
            url: "receive.php",
            data: ({dtnum: "00001"})
        })
        .done(function (msg) {
            alert("output: " + msg);

        })
.fail(function() {
    alert( "Posting failed." );
});

and this is my html

<input type="text" name="doctitle"><br>
<input type="text" name="doctype"><br>

im getting the desired output but what i want to do is pass the output for each row in php script to each designated html input

knowmeifyou
  • 217
  • 7
  • 17
  • 1
    Possible duplicate of [Basic PHP and AJAX](http://stackoverflow.com/questions/5298401/basic-php-and-ajax) – CoderPi Nov 25 '15 at 12:48
  • im reading it right now sir. hope that helps me – knowmeifyou Nov 25 '15 at 12:50
  • Not really enough code here to show the problem - I assume there is a form with multiple input elements, probably of various types? I guess you might serialise the form and send that to the php code and incorporate the fields in the output. Ideally post the html form and the sql – Professor Abronsius Nov 25 '15 at 12:51
  • i already updated the post sir. sample where i will put the output from php – knowmeifyou Nov 25 '15 at 12:59
  • @CodeiSir the thread you posted sir is not seperating the output and put it to the desired input but showing the output only from the php script – knowmeifyou Nov 25 '15 at 13:01
  • use JSON strings ... – CoderPi Nov 25 '15 at 13:02

1 Answers1

0

Change your JS to the following:

$.post("receive.php", {
    data: ({dtnum: "00001"})
})
.success(function (msg) {
    alert("output: " + msg);

})
.error(function() {
    alert( "Posting failed." );
});

Further reading: http://api.jquery.com/jquery.ajax/

Jono20201
  • 3,215
  • 3
  • 20
  • 33