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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.