Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress


I know that there is a very old answer that details unidentified index but using the methods there I can not figure out how to make isset work with the code I have. It is below but doesnt solve the issue.

Plus it my error is paired with the PREPARE error AND the fact that my understanding is that answer with ISSET is NOT a safe way anymore to prevent SQL injections. Someone please correct me if I am wrong. As per request I have also included the entire error message.

I am getting a couple of errors with the code below and am not sure why it thinks this isnt prepared properly. Can anyone shed light on this for me? Thanks.

for each line that has a $POST, it is telling me that the “Notice: Undefined index”

     if (!empty($_POST)) {
        global $wpdb;
        $table = "mytablenameplaceholder";
            if(isset($_POST['name']) && isset($_POST['emailaddress'])){
  $number1 = $_POST['name']; 
  $message = $_POST['emailaddress']; 
  $message = urlencode($message); 
        $data = array(
            'name' => $_POST['name'],
            'emailaddress'    => $_POST['emailaddress'],
            'phonenumber'    => $_POST['phonenumber']
        $format = array(
        $success=$wpdb->insert( $table, $data, $format );
            echo 'data has been saved' ; 
    } else {
    <form action="" method="post" >
        <input type="text"  id="name" name="name" value="John">
        <input type="text" name="email">
        <input type="text" name="phonenumber">
        <input type="submit">

I am also receiving a “Notice: wpdb::prepare was called incorrectly.” notice despite not having a prepare statement currently in the code. I know I need to add it.

enter image description here

Manny 4 months 0 Answers 10 views 0

Leave an answer