php code snippet not functioning

  • Unknown's avatar

    I am attempting to use the code snippet plugin and the code below for inserting a 1 into my MYSQL database. The db table just has 2 columns one for timestamp and one called “command” that receives integer values. The timestamp just defaults to a timestamp function upon insert.

    I use elementor as my editor and when I type my shortcode [phpshutdownkey] it is recognized. I then am adding a separate html button on the same page that should be activating the php db insert. It doesn’t work though not even seeing the first echo command. Not sure what I am doing wrong here.

    function shutdownkey( $atts ) {
    	//if the submit button is clicked, follow logic to insert record
    	if (isset($_POST['submit'])) {
        	$insert_value = 1;
            echo "button pressed";
    
        	//make a database connection
        	$conn = new mysqli('localhost', 'myuser', 'mypass', 'mydb');    
        	//prepared statement to insert the record
        	$stmt_insert_record = $conn->prepare("INSERT INTO MotorON (command) VALUES (?)");
        	$stmt_insert_record->bind_param("i", $insert_value);
        	$stmt_insert_record->execute();
        	$stmt_insert_record->close();
    	}
    }
    add_shortcode('phpshutdownkey', 'shutdownkey');
    

    button code:

    <!-- Form that will submit to the document's address ie. the same page-->
    <form method="post">
        <input type="submit" value="Shutdown" style="background-color: red;">
    </form>
  • What is the URL of the site you’re trying to use that on?

  • Unknown's avatar

    the site is still “coming soon”

  • I don’t see any sites under your account here that would support Elementor, so we need some more details.

    NOTE: We can only assist with websites hosted here at WordPress.com. If you’re using the WordPress software, but hosted elsewhere, you will need to reach out to your hosting provider or the WordPress.org community for guidance: https://wordpress.org/support/

  • Unknown's avatar

    the site domain is https://feynmaniot.com/

    using elementor pro

  • Ok, that is a self-hosted WordPress.org site, hosted with Bluehost, which we really can’t help with here.

    To clear up any confusion, WordPress.com and WordPress.org are two different entities: https://wordpress.com/support/com-vs-org/

    WordPress.org has complete documentation for self-hosted/installed versions of WordPress.org at https://wordpress.org/support/ and support at https://wordpress.org/support/forums/

    And, you can find Elementor’s support at https://elementor.com/support/

  • Unknown's avatar

    I do see that my account is pointing to an older website that doesn’t use elementor so i see where you are coming from

  • The topic ‘php code snippet not functioning’ is closed to new replies.