Sheils
asked on
What is the best way to update form with most recent entry
I am using ajax to run a php/mysql insert into query. That works fine.
What I now want to know is what is the best way to capture the id of the record that I have just entered.
I was thinking of running:
Select max(id) from table1
immediately after the insert into. Will that be ok or will there be conflict in the odd change that two person enters a record at the same time?
What I now want to know is what is the best way to capture the id of the record that I have just entered.
I was thinking of running:
Select max(id) from table1
immediately after the insert into. Will that be ok or will there be conflict in the odd change that two person enters a record at the same time?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Maybe this helps. If I understand your problem correctly?
http://stackoverflow.com/questions/12791455/php-variable-through-jquery-ajax-to-external-php
http://stackoverflow.com/questions/12791455/php-variable-through-jquery-ajax-to-external-php
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ray,
That a nice simple article you've got. Thanks.
I tried the following codes:
js
php
and got the following response:
1) How do I trigger the isset
2) As you can see I have comment out the $.ajax method that I was using previously. Can the response be used with the $ajax method which works fine except for not send back response
That a nice simple article you've got. Thanks.
I tried the following codes:
js
<script>
$( document ).ready(function() {
$(".button").click(function() {
alert($(this).attr("name"));
var d=$("input#datepicker").val();
var a=$("select#fldWithdrawingAccount").val();
datastring="send=&flddate=" + encodeURIComponent(d) + "&fldWithdrawingAccount=" + encodeURIComponent(a);
alert (datastring);
$.get("scripts/newExpenses.php", {myArg:datastring}, function(response){
$("#output p#target").html(response);
});
alert ("finish passing");
/*$.ajax({
type:"GET",
url : "scripts/newExpenses.php",
data: datastring,
success: function(reponse) {
$("#output p#target").html(response);
//$('.dataenterysubform').css({"visibility":"visible"});
},
error : function() {
alert("Sorry, there was a problem!");
},
})*/;
return false;
});
});
</script>
php
<?php
error_reporting(E_ALL);
include "connect.php";
echo "in php<br />";
echo 'GET: ';
var_dump($_GET);
echo "<br />date here: ".$_get['flddate'];
if (isset ($_get['send'])) {
echo "in if";
$Date = $_get['flddate'];
$WithdrawingAccount = $_get['fldWithdrawingAccount'];
$sql = "INSERT INTO `tbTransactions` (`fldDate`, `fldWithdrawingAccount`,`fldType`) VALUES (STR_TO_DATE('" . $Date . "', '%d %b %Y')," . $WithdrawingAccount . ",1)";
echo $sql;
mysqli_query($cnn, $sql) or die(mysqli_error($cnn));
$result=mysqli_query($cnn,"select @@IDENTITY");
$row=mysql_fetch_array($result);
echo $row[0];
}
echo "<br />after if";
mysqli_close($cnn);
?>
and got the following response:
in php
GET: array(1) { ["myArg"]=> string(53) "send=&flddate=16%20Jan%202013&fldWithdrawingAccount=4" }
date here:
after if
1) How do I trigger the isset
2) As you can see I have comment out the $.ajax method that I was using previously. Can the response be used with the $ajax method which works fine except for not send back response
ASKER
Ray,
Dis regard question 2 found a typo in code and response is know working in $.ajax. I am still be in question 1 because your approach is more straight forward, less code.
Dis regard question 2 found a typo in code and response is know working in $.ajax. I am still be in question 1 because your approach is more straight forward, less code.
ASKER
esolve,
The @@IDENTITY works fine just waiting on Ray's response before I complete question and distribute points
The @@IDENTITY works fine just waiting on Ray's response before I complete question and distribute points
What is the question at this point? If you're happy with your solution, I am happy with any distribution of points you want to make. I think I already have enough points to orbit Saturn, so it's not really an issue for me ;-)
ASKER
Ray,
I would like to use the method in your article:-
$.get("scripts/newExpenses .php", {myArg:datastring}, function(response){
$("#output p#target").html(response);
});
as I prefer it over the $.ajax method, but I can't get it to trigger the isset function. Can you tell me who to make it trigger.
I would like to use the method in your article:-
$.get("scripts/newExpenses
$("#output p#target").html(response);
});
as I prefer it over the $.ajax method, but I can't get it to trigger the isset function. Can you tell me who to make it trigger.
It may be that the issue lies here ...
if (isset ($_get['send'])) {
In PHP, variable names are case-sensitive. I think you might want ...
if (isset ($_GET['send'])) {
or maybe it should be ...
if (isset ($_GET['myArg'])) {
if (isset ($_get['send'])) {
In PHP, variable names are case-sensitive. I think you might want ...
if (isset ($_GET['send'])) {
or maybe it should be ...
if (isset ($_GET['myArg'])) {
ASKER
Thanks Guys
ASKER