mmarth
asked on
mysqli_insert_id always returns 0
mysqli_insert_id always returns 0 . could there be a server setting that is causing this?
i have an auto incremented record , nameId, being inserted.
i have an auto incremented record , nameId, being inserted.
Can you show us the code you're using?
ASKER
function openRS($query)
{
$prsSERVER = $GLOBALS['theSERVER'];
$prsUSERNAME = $GLOBALS['theUSERNAME'] ;
$prsPASSWORD = $GLOBALS['thePASSWORD'] ;
$prsDATABASE = $GLOBALS['theDATABASE'] ;
$connect = @mysqli_connect($prsSERVER ,$prsUSERN AME,$prsPA SSWORD, $prsDATABASE);
$result = mysqli_query($connect, $query);
return $result;
}
$mysqliConLink = openConnect();
if ($rsHits=mysqli_query($mys qliConLink ,$query))
{
$rowcount=mysqli_num_rows( $rsHits);
}
$query="INSERT INTO NamesToCheckList (parentId,LASTNAME,FIRSTNA ME,BUSNAME ,userId,ac tive,facil ityId,list Id)
VALUES ( '$parentId','$lastName','$ firstName' ,'$busName ','1','$ac tive','2', '$listId') ";
$rs=openRS($query);
$lastInsertId = mysqli_insert_id($mysqliCo nLink);
{
$prsSERVER = $GLOBALS['theSERVER'];
$prsUSERNAME = $GLOBALS['theUSERNAME'] ;
$prsPASSWORD = $GLOBALS['thePASSWORD'] ;
$prsDATABASE = $GLOBALS['theDATABASE'] ;
$connect = @mysqli_connect($prsSERVER
$result = mysqli_query($connect, $query);
return $result;
}
$mysqliConLink = openConnect();
if ($rsHits=mysqli_query($mys
{
$rowcount=mysqli_num_rows(
}
$query="INSERT INTO NamesToCheckList (parentId,LASTNAME,FIRSTNA
VALUES ( '$parentId','$lastName','$
$rs=openRS($query);
$lastInsertId = mysqli_insert_id($mysqliCo
To set your connection you're using this:
$mysqliConLink = openConnect();
but the function to connect to the database has another name:function openRS($query)
ASKER
function openRS($query)
{
$prsSERVER = $GLOBALS['theSERVER'];
$prsUSERNAME = $GLOBALS['theUSERNAME'] ;
$prsPASSWORD = $GLOBALS['thePASSWORD'] ;
$prsDATABASE = $GLOBALS['theDATABASE'] ;
$connect = @mysqli_connect($prsSERVER ,$prsUSERN AME,$prsPA SSWORD, $prsDATABASE);
$result = mysqli_query($connect, $query);
return $result;
}
{
$prsSERVER = $GLOBALS['theSERVER'];
$prsUSERNAME = $GLOBALS['theUSERNAME'] ;
$prsPASSWORD = $GLOBALS['thePASSWORD'] ;
$prsDATABASE = $GLOBALS['theDATABASE'] ;
$connect = @mysqli_connect($prsSERVER
$result = mysqli_query($connect, $query);
return $result;
}
ASKER
i get the same result with:
mysqli_query($mysqliConLin k, $query);
$lastInsertId = mysqli_insert_id($mysqliCo nLink);
it works if i use :
$query="SELECT MAX(nameId) AS lastId FROM NamesToCheckList";
mysqli_query($mysqliConLin
$lastInsertId = mysqli_insert_id($mysqliCo
it works if i use :
$query="SELECT MAX(nameId) AS lastId FROM NamesToCheckList";
You need to check and see if the query worked. Full instructions are in this article.
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
Quick summary:
1. Add error_reporting(E_ALL) to the top of all your scripts
2. Add var_dump() to print out every variable your scripts set
3. When a PHP instruction returns a value, print the value. For examples check the Return Values shown in the PHP manual:
http://php.net/manual/en/mysqli.query.php
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
Quick summary:
1. Add error_reporting(E_ALL) to the top of all your scripts
2. Add var_dump() to print out every variable your scripts set
3. When a PHP instruction returns a value, print the value. For examples check the Return Values shown in the PHP manual:
http://php.net/manual/en/mysqli.query.php
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
been trying to figure this out since mysql. worked with mysql_insert_id
P.S. you did misspell mysqli_insert_id
P.S. thanks Ray
P.S. you did misspell mysqli_insert_id
P.S. thanks Ray
Sorry for the mispelling... But I wrote mysqi_insert_id rather than mysqli_insert_id. So, in order to avoid to mix up mysql and mysqli functions, use mysqli_insert_id.
Thanks for points :-)
Thanks for points :-)