NYCPHP Meetup

NYPHP.org

[nycphp-talk] Bizarro Bug trying to insert after using mysql_insert_row

Kristina Anderson ka at kacomputerconsulting.com
Wed Apr 2 11:14:06 EDT 2008


Yes, sorry, I meant to say mysql_insert_id and corrected myself (it was 
late and I was working on this nonstop).

The ID value is correctly returned and the INSERT string builds 
correctly, so those are not the problems.  For whatever reason, after 
the INSERT is processed, the field that should contain the ID of the 
last record is not updating but remains the default value.

I inherited the system from others to debug, and because this is the 
last functionality that needs to be delivered before completion.  My 
best guess is that it might be something in the table structure that 
I'm missing, I've set up two fields one varchar and one int(11) to try 
to capture the returned ID value.  Both remain blank at this point.

> Hi Kristina:
> 
> On Tue, Apr 01, 2008 at 07:57:48PM -0700, Kristina Anderson wrote:
> > I'm pulling out the ID of the previously inserted row and then 
> > inserting that as a lookup value in a duplicate row (two rows one 
for 
> > edit mode one for published mode).
> > 
> > Various other places in the app this works fine and there really 
isn't 
> > any reason this should be happening.
> > 
> > The query runs fine if I do it from within phpMyAdmin -- but from 
the 
> > PHP page the query does not error out but the value in the lookup 
field 
> > remains the default value
> 
> You say you're using "mysql_insert_row."  I assume you mean PHP's 
> mysql_insert_id() function.  If so, there are two possible bugs that 
come 
> to mind.
> 
> 1) The table in question does not have auto_increment set for the 
primary 
> key on that table.  If that's not it...
> 
> 2) The PHP code has a bug...
> 
> You say this same logic works on other parts of the site.  So, do the 
> various parts of the site use the _same_ _exact_ 
files/lines/functions or 
> do you have separate function/include/whatever for each section of 
the 
> application?
> 
> If you're using separate code for different sections, obviously the 
PHP 
> code you're using for the problematic insert is where the bug is.  
> Perhaps the variable you assign the id to is different than the 
variable 
> you're using as the lookup value in the second query.
> 
> Again, if you're using separate code, you should refactor the system 
to 
> allow you to use the same code for the same purpose throughout the 
> system.
> 
> --Dan
> 
> -- 
>  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
>             data intensive web and database programming
>                 http://www.AnalysisAndSolutions.com/
>  4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
> 
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
> 




More information about the talk mailing list