Note that there are some explanatory texts on larger screens.

plurals
  1. POreturned ajax query data undefined
    primarykey
    data
    text
    <p>Hello I am attempting to create an ajax query but when my results are returned I get <strong>Undefined</strong> as a response. Except for the object called "hello" which returns back as "h" even though it is set to "hello". I have a feeling it has something to do with the way ajax is sending the data but i'm lost as to what may be the issue. Any help would be greatly appreciated.</p> <p><strong>here is the ajax</strong></p> <pre><code>function doSearch() { var emailSearchText = $('#email').val(); var keyCardSearchText = $('#keyCard').val(); var userNameSearchText = $('#userName').val(); var pinSearchText = $('#pin').val(); var passwordSearchText = $('#password').val(); $.ajax({ url: 'process.php', type: 'POST', data: { "hello": "hello", "emailtext": "emailSearchText", "keycardtext": "keyCardSearchText", "usernametext": "userNameSearchText", "pinText": "pinSearchText", "passwordtext": "passwordSearchText" }, dataType: "json", success: function (data) { alert(data.msg); var mydata = data.data_db; alert(mydata[0]); } }); } </code></pre> <p><strong>Then here is the php</strong></p> <pre><code>include_once('connection.php'); if(isset($_POST['hello'])) { $hello = $_POST['hello']; $emailSearchText = mysql_real_escape_string($_POST['emailSearchText']); $keyCardSearchText = mysql_real_escape_string($_POST['keyCardSearchText']); $userNameSearchText = mysql_real_escape_string($_POST['userNameSearchText']); $pinSearchText = mysql_real_escape_string($_POST['pinSearchText']); $passwordSearchText = mysql_real_escape_string($_POST['passwordSearchText']); $query = "SELECT * FROM Students WHERE (`User name`='$userNameSearchText' OR `Email`='$emailSearchText' OR `Key Card`='$keyCardSearchText')AND(`Password`='$passwordSearchText'OR `Pin`='$pinSearchText')"; $students = mysql_query($query); $count = (int) mysql_num_rows($students); $data = array(); while($student = mysql_fetch_assoc($students)) { $data[0] = $student['First Name']; $data[1] = $student['Last Name']; $data[2] = $student['Date of last class']; $data[3] = $student['Time of last class']; $data[4] = $student['Teacher of last class']; $data[5] = $student['Membership Type']; $data[6] = $student['Membership Expiration Date']; $data[7] = $student['Free Vouchers']; $data[8] = $student['Classes Attended']; $data[9] = $student['Classes From Pack Remaining']; $data[10] = $student['5 Class Packs Purchased']; $data[11] = $student['10 Class Packs Purchased']; $data[12] = $student['Basic Memberships Purchased']; $data[13] = $student['Unlimited Memberships Purchased']; $data[14] = $student['Groupon Purchased']; }; echo json_encode(array("data_db"=&gt;$data, "msg" =&gt; "Ajax connected. The students table consist ".$count." rows data", "success" =&gt; true)); }; </code></pre>
    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