Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieving data from JSON array (PHP) and populating textboxes
    primarykey
    data
    text
    <p>I'm trying to pull the data gathered from the MySQL query referenced below and populate the corresponding textboxes with that data:</p> <pre><code>&lt;?php header('Content-type: application/json'); $server = "••••"; $username = "••••"; $password = "••••"; $database = "••••"; $username_pull = $_POST['a_username']; $con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error()); mysql_select_db($database, $con); $sql = "SELECT uname, pword, fullname, phone_num, email_add, car_details FROM app_login WHERE uname = '$username_pull'"; $result = mysql_query($sql) or die ("Query error: " . mysql_error()); $records = array(); while($row = mysql_fetch_assoc($result)) { $records[] = $row; } mysql_close($con); echo $_GET['jsoncallback'] . json_encode($records); ?&gt; </code></pre> <p>If I insert in $username_pull = "admin", I get the following json info, so I know it works:</p> <pre><code>[{"uname":"admin","pword":"password","fullname":"John Smith","phone_num":"123-456-7890","email_add":"john@website.com","car_details":"2013 Black Cadillac ATS"}] </code></pre> <p>Here's my json callback function:</p> <pre><code>function fillTheGap() { var f_uname = $("#a_username").val(); $.ajax({ url: "login2.php", data: f_uname, dataType: "jsonp", jsonp: "jsoncallback", success: function(data) { $("#a_phonenum").val(data.phone_num); $("#a_fullname").val(data.fullname); $("#a_email").val(data.email_add); $("#a_cardetails").val(data.car_details); },}); } </code></pre> <p>Here's the form that initiates the data pulling:</p> <pre><code> &lt;form name="check_user" method="" action="post"&gt; Your Username: &lt;input id="a_username" name="a_username" type="text" onBlur="fillTheGap()"&gt; Your Full Name: &lt;input id="a_fullname" name="a_fullname" type="text"&gt; Your Phone Num: &lt;input id="a_phonenum" name="a_phonenum" type="text"&gt; &lt;input name="submit" type="button" value="Submit"&gt; &lt;/form&gt; </code></pre> <p>How do I make it to where it populates the textboxes with its corresponding ID name?</p> <p>I greatly appreciate everyone's help in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload