atticus Posted July 24, 2012 Share Posted July 24, 2012 This code is not presenting error messages and is not inserting the data as expected. Anything I'm missing? ///DB Connection $mysqli = new mysqli("localhost", "***", "***", "***"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } ////Hidden Form Information $service = $_GET['service']; $form = $_GET['form']; $confirmation = $_GET['confirmation']; $special = $_GET['special']; $function = $_GET['function']; ////Insert into DB and confirm if ($mysqli->query("INSERT INTO leads_main VALUES('$service','$form','$confirmation','$special','$function'") === TRUE) { printf("Table myCity successfully created.\n"); } Quote Link to comment https://forums.phpfreaks.com/topic/266192-msqli-problem-with-queries-wont-display-errors/ Share on other sites More sharing options...
atticus Posted July 24, 2012 Author Share Posted July 24, 2012 I checked the connection with mysqli ping and it says its ok: /* check if server is alive */ if ($mysqli->ping()) { printf ("Our connection is ok!\n"); } else { printf ("Error: %s\n", $mysqli->error); } Quote Link to comment https://forums.phpfreaks.com/topic/266192-msqli-problem-with-queries-wont-display-errors/#findComment-1364102 Share on other sites More sharing options...
atticus Posted July 24, 2012 Author Share Posted July 24, 2012 The following query outputs rows: if ($result = $mysqli->query("SELECT option_name FROM wp_options LIMIT 10")) { printf("Select returned %d rows.\n", $result->num_rows); } This must be the troubled code: if ($mysqli->query("INSERT INTO leads_main VALUES('$service','$form','$confirmation','$special','$function')") === TRUE) { printf("data inserted.\n"); } Quote Link to comment https://forums.phpfreaks.com/topic/266192-msqli-problem-with-queries-wont-display-errors/#findComment-1364106 Share on other sites More sharing options...
Pikachu2000 Posted July 24, 2012 Share Posted July 24, 2012 It may be because if you don't explicitly list the fields you're inserting into in the query, you must provide a value for all fields in the table. You should also be echoing mysqli_error() if the call to mysqli_query returns FALSE. Quote Link to comment https://forums.phpfreaks.com/topic/266192-msqli-problem-with-queries-wont-display-errors/#findComment-1364108 Share on other sites More sharing options...
atticus Posted July 24, 2012 Author Share Posted July 24, 2012 You are right Pikachu2000, I wasn't inserting anything into the id column so I needed to list fields explicitly. Thanks man! Quote Link to comment https://forums.phpfreaks.com/topic/266192-msqli-problem-with-queries-wont-display-errors/#findComment-1364111 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.