Cant INSERT row sql table php


When i try to insert table i was get unique id but there is no records in my database. I cant understand what is the problem i am not getting any error. My code was working but stop automatically maybe something is wrong in my phpmyadmin please tell me how to find main problem or how to fix this issue and that happen with only one table other table working fine. I was try to repair table : not work

i can see my auto increment id is stuck on 42470 cant add new row please help..

$sql = mysqli_query($mysqli,"INSERT INTO yt_view (id,uid,url,current,total,timelimit,point) VALUES ('','$reg->id','$url','0','$reg->views','$reg->timelimit','$reg->point')") or dir(mysqli_error($mysqli));
  mysqli_insert_id($mysqli); //Generated success but no record in db


When you do a


what do the table definitions look like?


Is there anything in the values you insert that might cause a problem? A single-quote anywhere, for example?

Also this bit

or dir(mysqli_error($mysqli));

has a typo.


Is it normal to insert an empty string as the id value?
I don't include the id in insert statements and let A_I do its thing.


You need to leave the id column out of the query. Auto increment takes care of itself.


I don't know if I'd say need to though I agree AUTO_INCREMENT can take care of itself and unless you have reason to do otherwise it's a very strong should.

No value was specified for the AUTO_INCREMENT column, so MySQL assigned sequence numbers automatically. You can also explicitly assign 0 to the column to generate sequence numbers, unless the NO_AUTO_VALUE_ON_ZERO SQL mode is enabled. If the column is declared NOT NULL, it is also possible to assign NULL to the column to generate sequence numbers. When you insert any other value into an AUTO_INCREMENT column, the column is set to that value and the sequence is reset so that the next automatically generated value follows sequentially from the largest column value.

For example, if "id" is auto_increment and you insert 10 rows without setting a value, they will be 1 to 10. If you then insert a row with an id value of 123, the next row inserted without setting a value the value will be 124, Values 11 to 122 will not exist. So I think in most cases it would be wise to let auto_increment do its thing unless missing values are of no importance. And there's the possible error condition of inserting a value that already exists to think about too.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.