i try to submit text to db, but in the db field not inserted any text.
can you analyze where my false?
i try like this.
Thanks for your help.
<script type="text/javascript">
$(document).ready(function() {
$('#myForm').submit(function() {
var namaklasifier = document.getElementByName("tfklasifier").value;
var inputpos= document.getElementByName("tacaripos").value;
var inputnet = document.getElementByName("tacarinet").value;
var inputneg = document.getElementByName("tacarineg").value;
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(data) {
$('#resultcoba').html(data);}
})
return false;
});
})
</script>
<form id="myForm" method="post" action="proses.php">
<td align="center" valign="top" style="width:420px"><textarea style="width:420px" name="tacaripos" rows="4" cols="70"><?PHP echo htmlspecialchars($_POST['tacaripos']);?></textarea></td>
<td align="center" valign="top" style="width:420px"><textarea style="width:420px" name="tacarinet" rows="4" cols="70"><?PHP echo htmlspecialchars($_POST['tacarinet']);?></textarea></td>
<td align="center" valign="top" style="width:420px"><textarea style="width:420px" name="tacarineg" rows="4" cols="70"><?PHP echo htmlspecialchars($_POST['tacarineg']);?></textarea></td>
</tr>
<td align="center"><input type="submit" name="btklasifier" id="btklasifier" value="Buat" /></td></form>
proses.php
<?php
$namaklasifier=$_POST['namaklasifier'];
$jadipos=$_POST['inputpos'];
$jadinet=$_POST['inputnet'];
$jadineg=$_POST['inputneg'];
$link=mysqli_connect("localhost", "root", "","skripsi");
mysqli_select_db($link,"skripsi");
mysqli_query($link,"INSERT INTO namaklasifier(username,datapos,datanet,dataneg,user) VALUES('$namaklasifier','$jadipos','$jadinet','$jadineg','{$_SESSION['username']}')"); ?>
Thanks :)
You are trying to access the GET data under the variable names you have declared here:
var namaklasifier = document.getElementByName("tfklasifier").value;
var inputpos= document.getElementByName("tacaripos").value;
var inputnet = document.getElementByName("tacarinet").value;
var inputneg = document.getElementByName("tacarineg").value;
Yet you are sending them using $(this).serialize() which means you must access the GET variables using the input name as this is what serialize does (creates an object from the form elements using their names). e.g.
$jadipos=$_POST['tacaripos'];
$jadinet=$_POST['tacarinet'];
$jadineg=$_POST['tacarineg'];
Also you need to change $_GET to $_POST as that is the method you are using.
In proses.php, change the $_GET into $_POST.
Since you are using POST method to submit data, naturally, you have to use the $_POST variables.
They are POST values not the GET ones
$jadipos=$_POST['inputpos'];
$jadinet=$_POST['inputnet'];
$jadineg=$_POST['inputneg'];
And try to use mysqli_* functions or PDO statements,instead of mysql_* functions due to they are deprecated
EDIT:also try like
var namaklasifier = document.getElementByName("tfklasifier").value;
var inputpos= document.getElementByName("tacaripos").value;
var inputnet = document.getElementByName("tacarinet").value;
var inputneg = document.getElementByName("tacarineg").value;
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: {inputpos:inputpos,inputnet:inputnet,inputneg:inputneg},
success: function(data) {
$('#resultcoba').html(data);}
})
return false;
});
Related
Here is my jquery function. i call this function on blue event. there are more than one records in list. i want particular rojmel_id and weight on blur event but i am not able to get. can anyone help me in this issue.
<script type="text/javascript">
function getweight(thisObj)
{
var row = $(thisObj).parents('.row');
var rojmel_id = row.find('.rojmel_id').val() != '' ? row.find('.rojmel_id').val() : 0;
var dataString = "rojmel_id=" + rojmel_id;
$.ajax({
type: "POST",
url: "updateWt.php",
data: dataString,
success: function (data){
}
});
}
</script>
Here is my html code
{section name=sec loop=$clientArray}
<tr>
<td>{$clientArray[sec].rojmel_date}</td>
<td>{$clientArray[sec].party_name}</td>
<td>{$clientArray[sec].item_nm}</td>
<td>{$clientArray[sec].marko}</td>
<td><input type="hidden" class="rojmel_id" name="rojmel_id" value="{$clientArray[sec].rojmel_id}">
<input type="text" name="weight" value="{$clientArray[sec].weight}" onblur="getweight(this);"></td>
</tr>
{/section}
</tbody>
Try this hope it work! and can you tell where you have been declared .row class.
Here is your solution: Solution JSBin
<!-- add class to <tr> then -->
{section name=sec loop=$clientArray}
<tr class="row">
<td>{$clientArray[sec].rojmel_date}</td>
<td>{$clientArray[sec].party_name}</td>
<td>{$clientArray[sec].item_nm}</td>
<td>{$clientArray[sec].marko}</td>
<td><input type="hidden" class="rojmel_id" name="rojmel_id" value="{$clientArray[sec].rojmel_id}">
<input type="text" name="weight" value="{$clientArray[sec].weight}" onblur="getweight(this);"></td>
</tr>
{/section}
</tbody>
<script type="text/javascript">
function getweight(thisObj)
{
var row = $(thisObj).closest('tr.row');
var rojmel_id = row.find('.rojmel_id').val() ? row.find('.rojmel_id').val() : 0;
var dataString = "rojmel_id=" + rojmel_id;
$.ajax({
type: "POST",
url: "updateWt.php",
data: dataString,
success: function (data){
}
});
}
</script>
pleae note that i m trying jump to test.php page from index.php/html using ajax and mysql, simple if text-input not found in table so it should go to test.php else stay on index.php/html page with ajax alerts, but from index page everytime receiving NOT AVAILABLE and sometime submit button not functional, below code FYR...
//index.php $(document).ready(function() {
//default form not submitted
$("#submit").data("submitted",false);
//preventing enter key in input field from submitting form
$("#welcome").on("submit", function(e){
if($('#submit').data("submitted")===false) {
e.preventDefault();
}
});
//trigger form submission
$("#submit").on("click",function(){
validate();
});});
//default form not submitted
//$("#submit
function validate() {
var num = $('#invst_num').val();
$.ajax({
type: 'POST',
url: 'check_test.php',
data: num,
cache: false,
dataType: "json",
success: function(data) {
if(data){
alert("NOT AVAILABLE");
} else {
$("#submit").data("submitted", true);
$("#welcome").submit();
}
}}</script> <form action="check_test.php" method="post" name="welcome" id="welcome" /> <table width="550" border='0' align='center' cellpadding='0' cellspacing='0'> <tr>
<td align="center"><label>
Enter Inv. # *:
<input name="invst_num" type="text" id="invst_num" size="40" />
<input name="submit" type='submit' id='submit' /> </label></td> </tr></table> </form>
//check_test.php <?php
include ("config/config.php");
//get the username
if (isset($_POST['submit'])) {
$invst_num = $_POST['invst_num'];
//mysql query to select field username if it's equal to the username that we check '
$sql = mysql_query("select invst_num_ar from shareholders_ar where invst_num_ar = '$invst_num' ");
if ($result = mysql_num_rows($sql)>0) {
echo ($result);
}
}
?>
// if not found...test.php should load
<html>
<form
...
Register Data
/form>
</html>
Your conditional is backwards
if(data){
Should be
if(!data){
Or the alert should be flipped with the listener adding logic.
var num = $('#invst_num').val();
$.ajax({
type: 'POST',
url: 'check_test.php',
data: num,
ajax call is sending value frome data key, so you send only the text field content.
You probably should send sth like this:
$.ajax({
type: 'POST',
url: 'check_test.php',
data: { 'invst_num': num },
...
Open Dev tools in your browser and check what content is being sent during ajax call.
I'm stuck in multiple input. My code is not showing all data. below is the html I am using:
<form id="matkul" class="form-horizontal" method="POST">
<table class="table table-condensed">
<thead>
<tr>
<th>Matakuliah</th>
<th>Data Lain</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</form>
<button id="post" type="submit">Save</button>
<button id="get">Get Data!</button>
below is the code to get the data
<script>
$(document).ready(function() {
$("#get").click(function() {
var url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22https%3A%2F%2Funisys.uii.ac.id%2Fuii-ras%2Fmatakuliah.asp%3Fidx%3D1%26session_id%3DxxbKiKJawuyrbaaiJ3Kabybabi3JJiKJrJyb3wiuKbbry0JbKiKbKr0yyrKK15933511%26no_mhs%3D%22&format=json';
$.getJSON(url,
function(data) {
var id = data.query.results.body.table.tr.td.table.tr[2].td.table.tr;
for (var i = 1; i <= id.length; i++) {
$("<tr> <td> <input name='fmatakuliah' value='"+id[i].td[1].a.content+"'> </td> <td> <input name='fdata' value='" + id[i].td[1].a['href'] + "'> </td> </tr>").appendTo("#matkul tbody");
};
});
});
});
</script>
from the above code output will be
Matakuliah Data Lain
StringOne OtherData
StringTwo OtherData
below is the ajax post code, but when it is already sending the data, the alert does not show all the data
<script type="text/javascript">
$(document).ready(function(){
$("#post").click(function(){
string = $("form").serialize();
alert(string); // this alert is normal, show all data
$.ajax({
type: "GET",
url: "/save.php",
data: string,
success: function(data){
alert("Success!"+data); //this not normal, not show all data
}
});
});
});
</script>
below is the code on save.php
print_r($_GET);
The latest response is showing like this
Array
(
[fmatakuliah] => Wide Area Network
[fdata] => matakuliahdetail.asp?session_id=xxbKiKJawuyrbaaiJ3Kabybabi3JJiKJrJyb3wiuKbbry0JbKiKbKr0yyrKK15933511&mk=52323605&kur=2010
)
My question is how to show all data and save it to the database?
It looks like you need to change the AJAX type from GET to POST:
$.ajax({
type: "POST",
url: "/save.php",
data: string,
success: function(data){
alert("Success!"+data); //this not normal, not show all data
}
});
i'm using jquery tabs..
i'm use tabs-1 as input form and tabs-2 as show input data...
i want after submit..all value inside textfield which have been type at tabs-1 can copy into textfield at tabs-2...
where part that i must modify?at form or at process page?what's code that can make it works?
<script type="text/javascript">
$(document).ready(function() {
$("#input").click(function() {
if($("#submit").valid()) {
var params=$("#submit").serialize();
$.ajax({
type:"post",
url:"process1.php",
data:params,
cache :false,
async :false,
success : function() {
that is for submitting form inside tabs-1...at tabs-2:
<tr>
<td width="100"><input type="text" id="showline" name="showline"<? echo "$_postVar('line')" ?>/></td>
<td width="100"><input type="text" id="showmodel" name="showmodel"<? echo "$_postVar('model')" ?>/></td>
<td width="100"><input type="text" id="showNIK" name="showNIK"<? echo "$_postVar('id')" ?>/></td>
</tr>
Well, if I understand this correctly, you can use the callback on the AJAX function to do that (so that the submitted info is only displayed if the request was successful):
[...]
success : function() {
$('#showline').val($('#faline').val());
$('#showmodel').val($('#modelnm').val());
$('#showNIK').val($('#NIK').val());
};
[...]
assuming that #faline, #modelnm and #NIK are the IDs of the input fields in the form from which the data is being submitted.
Also, in the HTML you don't need to echo anything anymore (which has incorrect syntax - it would be value="<? echo ... ?>" anyways) since the values will be added by jQuery.
Hope this helps !
$("#model").change(function() {
var barcode;
barCode=$("#model").val();
var data=barCode.split(" ");
$("#model").val(data[0]);
$("#serial").val(data[1]);
var str=data[0];
var matches=str.match(/[T|EE|EJU].*D/i);
$("#input").click(function() {
if($("#submit").valid()) {
var params=$("#submit").serialize();
$.ajax({
type:"post",
url:"process1.php",
data:params,
cache :false,
async :false,
success : function() {
$('#showline').val($('#line').val());
$('#showmodel').val($('#model').val());
$('#showNIK').val($('#id').val());
$("#model").val("");
$("#serial").val("");
$("#line").val("");
i put freekOne code before set .val("");
I'm writing a store system for my game,
it worked quite well until I found out that it only takes the amount of first entered Item.
function pbuy(buyitem) {
var amountc = "amount-"+buyitem,
var amount = $("#"+amountc+"").val();
$.ajax({
type: "POST",
url: "store2.php",
data: "buyitem="+ buyitem+"&amount="+amount,
success: function(resp){
document.getElementById('ajaxDiv').innerHTML = resp;
},
error: function(e){
alert('Error: ' + e);
}
});
}
I'm trying to give it it the Id of the form like so:
function pbuy(buyitem) { var amountc = "amount-"+buyitem, var amount = $("#"+amountc+"").val();
But nothing happens.
The code the creation of the forms is:
<tr>
<td class='items' width='80%' align='center' valign='top'>
<?PHP echo $itemstore->itemname;?>
</td>
<td width="20%">
Price:<?PHP echo $itemstore->newprice;?>
<form method="post">
<input type='text' id='amount-<?PHP echo $row;?>)' />
<input name="itembid" type="button" onclick="pbuy(<?PHP echo $row;?>)" value="Buy" />
</form>
</td>
</tr>
If I hardcode the amount in the ajax function it all runs fine like it should.
You're getting a javascript error before the AJAX-request is being sent since you are defining your amountc and amount variables separated by a comma. Either do
var amountc = "amount-"+buyitem;
var amount = $("#"+amountc+"").val();
semicolon separated, or keep the comma and skip the second var
var amountc = "amount-"+buyitem,
amount = $("#"+amountc+"").val();
Did you checked the response of the AJAX request?