0

i am facing this error, please help me.

<?php
 /*Plugin Name: Contact Form
 Plugin URI: http://localhost/redspark/wp-admin
 Description: Contact Form Create & Retrive By Ajax
 Author: Shifa Memon
 Author URI: http://localhost/redspark/wp-admin
 Version: 1.0 */
 function custom_contact_form_create(){
// echo "Active";
// die();
global $wpdb;
global $table_prefix;
$table = $table_prefix . 'contact_us';
    $sql = "CREATE TABLE 'wp_contact_us' (
      `id` int(50) NOT NULL PRIMARY KEY AUTO_INCREMENT,
      `name` varchar(50) NOT NULL,
      `email` varchar(100) NOT NULL,
      `subject` text NOT NULL,
      `message` longtext NOT NULL,
      `timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON 
       UPDATE current_timestamp())";
       $wpdb->query($sql);
}
register_activation_hook(__FILE__,'custom_contact_form_create');

function custom_contact_form_delete(){
   global $wpdb;
   global $table_prefix;
   $table = $table_prefix.'contact-us';
   $sql = "DROP TABLE $table";
   $wpdb->query($sql);
   // echo "Deactivate";
  }
  register_deactivation_hook(__FILE__ ,'custom_contact_form_delete');

    ?>

enter image description here

4
  • 3
    you should use the wpdb prefix variable instead of hardcoding wp_ to avoid conflicts and support multisite, and dbDelta to create the table. Also us the triple back tick syntax for code highlighting instead of indenting, it will be easieer
    – Tom J Nowell
    Commented Jun 18, 2021 at 12:20
  • i try with dbDelta but error is occur Commented Jun 18, 2021 at 12:39
  • dbDelta is very particular about how it's used and the formatting of the code. You also need to include a particular file before using it. Is the code in your question the entire plugin?
    – Tom J Nowell
    Commented Jun 18, 2021 at 15:30
  • yes you are right, but i didn't use dbDelta , without using this i fixed it..error was in formatting. you can see at below i posted answer.. Commented Jun 21, 2021 at 12:10

1 Answer 1

0

finally plugin is activated...

enter image description here

this is code...

enter image description here

2
  • What was the fix? It looks like you just removed the close tag ?> ?
    – Rup
    Commented Jun 18, 2021 at 13:17
  • I have placed a screenshot so the php close tag does not appear.. it was a little mistake u see code properly.. Commented Jun 18, 2021 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.