1

I'm trying to get a value (mysql_insert_id) after my form was submitted by ajax and form validation (jquery.validationEngine) but without success..

$(document).ready(function()
{
        $("#form1").validationEngine('attach',
        {
            autoHidePrompt:true,showOneMessage:true,
            onValidationComplete: function(form, status)
                {
                    if(status === true)
                        {

                           formget(document.getElementById('form1'),'page.php');

           TINY.box.show({html:'The entry (i want the id here..) has been updated successfully!',animate:false,close:false,mask:false,boxid:'success',autohide:2,top:5});
}
          else
{
          TINY.box.show({html:'Please check the form and try  again',animate:false,close:false,mask:false,boxid:'error',autohide:2,top:5});
}
}  
});

My page.php file

$query="INSERT INTO users (userid,title,)VALUES ('".$_SESSION['id']."', '".$_REQUEST['title']."')"; $result=mysql_query($query);
$id = mysql_insert_id();
Efi
  • 11
  • 4
  • Please note that PHP's `mysql_xxx()` functions are deprecated and not recommended for use. Code should be amended to use the newer `mysqli` or `PDO` extensions instead. – SDC Jan 24 '13 at 11:39
  • yes i know - mysqli_insert_id(). :-) – Efi Jan 24 '13 at 11:57
  • Please also be aware that using `$_SESSION` and `$_REQUEST` in an `INSERT` query whitout sanitizing the user submitted data could lead to **serious** security issue and expose your application to MySQL injection attacks. Have a look at [How to prevent SQL injection in PHP?](http://stackoverflow.com/questions/60174/how-to-prevent-sql-injection-in-php) – endorama Jan 24 '13 at 14:44
  • no one can help me with this? – Efi Jan 28 '13 at 07:19

1 Answers1

0
$query="INSERT INTO users (userid,title,)VALUES ('".$_SESSION['id']."', '".$_REQUEST['title']."')"; $result=mysql_query($query);
$id = mysql_insert_id();
echo mysql_error();

look at the error message;

Andrej Bestuzhev
  • 674
  • 6
  • 10
  • everything working good for me i just can't get the value ($id) back that i can use it for other function. – Efi Jan 24 '13 at 11:14