Jump to content

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.

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.