Lamez Posted January 13, 2010 Share Posted January 13, 2010 I am making some changes to an existing website. I did not write the code, the code is horrid. Any who, I have this query: $query = "INSERT INTO `games` (sport,hsid,homescore,vsid,visitorscore,type,`where`,location,date,time,found) VALUES ('$sport','$hq[id]','$homescore','$vq[id]','$visitorscore','$type','Here','$location','$date','$time','1')"; mysql_query($query) or die(mysql_error()); It looks very odd to me, it has a WHERE and a HERE, why? Why not use a update query? Unless this does not update. I am not sure. However, the ID that is inserted is this: 2147483647 (the highest prime number known so far: http://en.wikipedia.org/wiki/2147483647) I am thinking it is this very odd insert query, if not I must dig a little deeper. Any Ideas? Oops: I had a brain fart, the where is a column in the DB, and the here is the value! Man, I am dumb. Does any one have any idea why I get this as the ID? Link to comment https://forums.phpfreaks.com/topic/188352-bug-in-php-or-invalid-query/ Share on other sites More sharing options...
MadTechie Posted January 13, 2010 Share Posted January 13, 2010 2147483647 is the highest AUTO_INCREMENT, you can have, so I'll assume you have 2147483647 records! either that or sort by ID and find the highest and set the AUTO_INCREMENT to that! Link to comment https://forums.phpfreaks.com/topic/188352-bug-in-php-or-invalid-query/#findComment-994331 Share on other sites More sharing options...
Lamez Posted January 13, 2010 Author Share Posted January 13, 2010 How can I set the auto_increment? There is tons of records in the database, but the highest id is 9736. I am thinking about generating a number from 9757 to 30000 as a quick fix. Link to comment https://forums.phpfreaks.com/topic/188352-bug-in-php-or-invalid-query/#findComment-994333 Share on other sites More sharing options...
MadTechie Posted January 13, 2010 Share Posted January 13, 2010 SQL command ALTER TABLE `games` AUTO_INCREMENT =9737 or ALTER TABLE `games` AUTO_INCREMENT =MAX(ID) + 1 Link to comment https://forums.phpfreaks.com/topic/188352-bug-in-php-or-invalid-query/#findComment-994340 Share on other sites More sharing options...
Lamez Posted January 13, 2010 Author Share Posted January 13, 2010 thanks, I will try that solution next. I built this function: <?php function makeNum(){ $q = mysql_query("SELECT id FROM games WHERE id = '$num'"); $n = 1; //Starters. while($n != 0){ if(!isset($_SESSION['dbNum'])){ $_SESSION['dbNum'] = mysql_num_rows(mysql_query("SELECT id FROM games")); } $num = rand($_SESSION['dbNum'] , 2147483647); $n = mysql_num_rows($q); } return $num; } echo makeNum(); ?> I think it might work, what do you think? Link to comment https://forums.phpfreaks.com/topic/188352-bug-in-php-or-invalid-query/#findComment-994343 Share on other sites More sharing options...
MadTechie Posted January 13, 2010 Share Posted January 13, 2010 Is the ID current used in other database records ? if it is then an update could be a pain, but i would probably create a function to run once to clean up the data, rather than a function to attempt to get around it, as it could cause problems later will affect performance from the start Link to comment https://forums.phpfreaks.com/topic/188352-bug-in-php-or-invalid-query/#findComment-994354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.