Jump to content

$msqli problem with queries (won't display errors)


atticus

Recommended Posts

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");
}

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");
}

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.