TwinkiBro Posted July 23, 2016 Share Posted July 23, 2016 (edited) Alright so Im not sure what Im doing wrong here, but Its not giving me any errors or such but its not inserting anything into the SQL either with this query. function insertVehicle($vehicleid, $color1, $color2, $posX, $posY, $posZ, $vw, $int) { global $handler; $query = "INSERT INTO vehicles (VehID, Color1, Color2, PosX, PosY, PosZ, VW, INT) VALUES ($vehicleid, $color1, $color2, $posX, $posY, $posZ, $vw, $int)"; mysqli_query($handler, $query); } Function usage insertVehicle(411, 255, 255, 0.00, 0.00,0.00, 12, 10); SQL structure https://postimg.org/image/qysshlrh3/ Edited July 23, 2016 by TwinkiBro Quote Link to comment https://forums.phpfreaks.com/topic/301565-sql-insert-no-errors/ Share on other sites More sharing options...
mac_gyver Posted July 23, 2016 Share Posted July 23, 2016 Its not giving me any errors that's because there is no error handling in your code for the database statements. the easiest way of handling things like database statement errors are to use exceptions. to enable exceptions of the msyqli statements, add the following lines of code, preferably before you make the database connection so that connection errors will also throw an exception - $driver = new mysqli_driver(); $driver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT; // MYSQLI_REPORT_ALL <- w/index checking; w/o index checking -> MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT; then, if you have php's error_reporting set to E_ALL and display_errors set to ON, any database statement errors will throw an exception and be caught by php, which will report a fatal runtime error that contains the actual msyqli error information. after you add the error handling, and find which column name is producing a sql sytnax error, because it is a reserved keyword, you need to use a prepared query to supply the data values to the sql statement, rather than putting them directly into the sql query. the PDO extension is much easier and more consistent than the msyqli extension, especially for prepared queries. if you can, switch to the PDO extension. Quote Link to comment https://forums.phpfreaks.com/topic/301565-sql-insert-no-errors/#findComment-1534903 Share on other sites More sharing options...
Psycho Posted July 23, 2016 Share Posted July 23, 2016 As mac_gyver states you have no error handling. You may have other problems, but the only thing I can "see" wrong in your code is the field name "INT". That is a reserved word in MySQL, so you can use it normally as a field name like that. You can either change the field name or you need to enclose the filed name in backticks to tell the MySQL engine that you are referring to the field name and not using the INT command. $query = "INSERT INTO vehicles (VehID, Color1, Color2, PosX, PosY, PosZ, VW, `INT`) VALUES ($vehicleid, $color1, $color2, $posX, $posY, $posZ, $vw, $int)"; Quote Link to comment https://forums.phpfreaks.com/topic/301565-sql-insert-no-errors/#findComment-1534909 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.