php - $_POST empty when using $.post -
here problem: want make database search using php form. have form , want work if there empty fields (as more fields u fill, more specific answer u get). using jquery first values form , send $.post actual php file connects database , search. giving empty fields specific value recognized in php file 'empty' field can make proper sql query. problem find $_post variables empty, though variables in jquesry script set properly. using method in other cases , works fine. have no idea if matter loading form inside main div using jquery well. alert(data) function job: in prompt window can see results of search reloading profile.php gives me nothing. here code:
form:
<script type="text/javascript" src="scripts/admin.js"></script> <form id="form_admin"> <table cellpadding="0" cellspacing="0" width="180"> <p style="line-height: 2cm; "> <tr> <td width="50" class="label1">imię:</td> <td> <input id="imie" type="text" value=""> </td> </tr> <tr> <td width="50" class="label1">nazwisko:</td> <td> <input id="nazwisko" type="text" value=""> </td> </tr> <tr> <td width="50" class="label1">numer telefonu:</td> <td> <input id="telefon" type="text" value=""> </td> </tr> <tr> <td align="center" colspan="2"> <input type="button" id="register" value="pokaż!"> <br> </td> </tr> </p> </table> </form> admin.js
$(document).ready(function () { $("#register").click(function () { if ($("#imie").val() != "") { var imie = $("#imie").val(); } else { var imie = 'nic'; } if ($("#nazwisko").val() != "") { var nazwisko = $("#nazwisko").val(); } else { var nazwisko = 'nic'; } if ($("#telefon").val() != "") { var telefon = $("#telefon").val(); } else { var telefon = 'nic'; } $.post("profile.php", { name: imie, surname: nazwisko, telephone: telefon }, function (data) { alert(data); }); $("#main").load('profile.php'); }); }); profile.php
<? php include('config.php');#logging database if (isset($_post['name']) && isset($_post['surname']) && isset($_post['telephone'])) { $imie = $_post['name']; $nazwisko = $_post['surname']; $telefon = $_post['telephone'];#then sql queries go... while ($user = mysql_fetch_assoc($select)) { echo 'order_id zamówienia: '.$user['orderinfo_id']; echo 'data zamówienia: '.$user['date_placed']; } while ($user = mysql_fetch_assoc($select2)) { echo 'suborder_id: '.$user['subitem_id']; echo 'ilość: '.$user['quantity']; echo 'koszt zamówienia: '.$user['cost']; } } else { echo "$_post variables aren't set"; } ?> edit: have installed firebug , checked post profile.php after submitted data , contains variables expected.
try changing $.post function to:
$.post("profile.php", { data: "&name=" + imie + "&surname=" + nazwisko + "&telephone=" + telefon }, function (data) { alert(data); });
Comments
Post a Comment