This string for some reason does not enter data into the database .. if I check $result2 for TRUE $result2 FALSE while the database is turned on, the name of the table is spelled correctly, the variables all exist

 $result2 = mysql_query("INSERT INTO coalitions (name, avatar, creators, stat) VALUES ('$name', '$logotip', '$creatorid', '$stat')",$db);//заносим в базу сообщение 

Added by:

table fields - id - auto increment - int9; name varchar225; avatar varchar225; creators varchar225; stat int1 дефаулт 0; int9; name varchar225; avatar varchar225; creators varchar225; stat int1 дефаулт 0;

  • one
    Look at the error text echo mysql_error (); - evz
  • Too little information. Lay out all the code, the problem can be like data mismatch or the unique field is and you enter the same. All code lay out? - duddeniska
  • pastebin.com/YEUtGf7V here is the complete code from the beginning of receiving variables through POST and up to the problem line - DanteLoL
  • gives out nothing unfortunately .. - DanteLoL
  • one
    Try the following: - set error_reporting (E_ALL); - $ db exactly the ID of the connection with the database? - print the request, try to execute it through the console. - evz

2 answers 2

Try to make the request itself directly to the base console, i.e. “clean” SQL with suggested values ​​and see. Although the code in terms of syntax is clear of errors - I suspect that the type of the fields (or their length) does not correspond to the data that they are trying to write. Lay out a printout of the team DESCRIBE coalitions; - let's see what types of fields are used - maybe there the name defined as datetime .. And anyway, write to us all the data values ​​that the script is trying to write to the table.

UPD: Line 23

 $creatorid = $myrow['id']; 

The value of $myrow['id'] already "empty" in this line. Therefore, print out all the data values ​​that should be written to the table before the SQL query, namely:

 echo $name; echo $logotip; echo $creatorid; echo $stat; 
  • Here is the screen of the y.jp0.ru/opt/1/8b4155a17cdeed118c4a48b97e6f7da.jpg table and the variables are all normal .. are of type String - DanteLoL
  • one
    The point, as I have already mentioned, is most likely not in the table, but in the fact that the $creatorid variable is empty. Printing it through echo $creatorid; or even put a string of SQL queries on the screen, just for debugging: echo "INSERT INTO coalitions (name, avatar, creators, stat) VALUES ('$ name', '$ logotip', '$ creatorid', '$ stat'" before you implement it in mysql_query - void
  • As it turned out, this problem was not the only one with the script - other scripts stopped working where there is an INSERT command - despite the fact that they didn’t undergo the change, it’s just as if the Insert command was disconnected ... - DanteLoL
  • I understand everything, but when you try to do INSERT , because SOMETHING writes in reply? I mean a mistake - maybe you should bring it here? Well, we enter the SHOW GRANTS FOR 'root'@'localhost'; command SHOW GRANTS FOR 'root'@'localhost'; where instead of 'root'@'localhost' you need to substitute your user and host (it is possible to leave localhost - it depends on your hosting configuration or if everything is local). That writes? Maybe the user does not have rights to INSERT ? - void

I found everything! I have 6 fields in the table - 1 id with auto-increment - 2 name 3 avatar 4 creators 5 users 6 stat - 1e is auto-increment - 6e it has a default value! - if I drive in the data completely in the request - I fill in 2 3 4 and 5 fields, then the request passes if, for example, I fill only one or two, then the request does not pass! Previously, it was not so now why?

  • Yet it is not easy to answer the "why" without having the parameters of the table and the base as a whole. Read about UPDATE with skip attributes . Just say why something is wrong with you with the base, alas, I can’t remotely. - void
  • Well, for example, the base there is a cell id1 id2 id3 & id4 they have no default values, I make a query like "INSERT INTO mayabaza (id1, id2, id3) VALUES ('53', '22', '25')"; and he does not pass with this error does not write anything !! but if I specify how to fill in all 4 fields like this "INSERT INTO mayabaza (id1, id2, id3, id4) VALUES ('53', '22', '25', '' 1 ')"; that's all okay if I put for id4 "by default" then the 1st option also passes .. likewise with any other field. - DanteLoL