Title: Adding PHP Code
Last modified: December 16, 2020

---

# Adding PHP Code

 *  [aratc](https://wordpress.org/support/users/aratc/)
 * (@aratc)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/adding-php-code-2/)
 * I’m encountering a fatal error when trying to add PHP code to my website

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [Vlad](https://wordpress.org/support/users/vladytimy/)
 * (@vladytimy)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/adding-php-code-2/#post-13797921)
 * Hi, [@aratc](https://wordpress.org/support/users/aratc/)
 * Please tell us more. Where are you adding your code and what is that code.
 *  Thread Starter [aratc](https://wordpress.org/support/users/aratc/)
 * (@aratc)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/adding-php-code-2/#post-13798395)
 * I want to add it using elementor pro with plugin, is there another way to upload
   it?
    And here is my code:
 *     ```
       <!DOCTYPE html>
       <html>
       <style type="text/css">
           .input1 {
               background-color: #3498db;
               color: white;
               border-color: #3498db;
               width: 70px;
          }
           .input2 {
               width: 250px;
           }
           .input2::placeholder {
               text-align: right;
           }
           .table1, 
           .table2 {
               border: 1px solid black;
           }
           .table1 {
               background-color: #3498db;
           }
           .table2 {
               background-color: #d9d9d9;
               text-align: center;
           }
       </style>
       <body> 
       <form method="post">
       <input class="input1" type="submit" name="submit" value="تحقق">
       <input class="input2" type="text" name="test" placeholder="رقم الشهادة">
   
       </form>
   
       </body>
       </html>
       <?php
       $con = new PDO("mysql:host=localhost;dbname=aratcnet_certificates",'root','');
   
       if (isset($_POST["submit"])) {
       	$int = $_POST['test'];
       	$sth = $con->prepare("SELECT * FROM <code>new_table</code> WHERE sit_num = '$int'");
   
       	$sth->setFetchMode(PDO:: FETCH_OBJ);
       	$sth -> execute();
   
       	if($row = $sth->fetch())
       	{
       		?>
       		<br><br><br>
       		<table>
       			<tr>
       				<th class="table1">Certificate No.</th>
       				<th class="table1">Full Name</th>
       				<th class="table1">Course Title</th>
       				<th class="table1">Date Of Issue</th>
       				<th class="table1">Trainer</th>
       			</tr>
       			<tr>
       				<td class="table2"><?php echo $row->sit_num; ?></td>
       				<td class="table2"><?php echo $row->candidate_name; ?></td>
       				<td class="table2"><?php echo $row->course_name; ?></td>
       				<td class="table2"><?php echo $row->date_of_issue; ?></td>
       				<td class="table2"><?php echo $row->trainer; ?></td>
       			</tr>
       		</table>
       <?php 
       	}
       		else {
       			echo "رقم الشهادة غير صحيح، الرجاء التأكد من الرقم وإعادة المحاولة";
       		}
       }
       ?>
       ```
   
    -  This reply was modified 5 years, 3 months ago by [bcworkz](https://wordpress.org/support/users/bcworkz/).
      Reason: code fixed
 *  [Vlad](https://wordpress.org/support/users/vladytimy/)
 * (@vladytimy)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/adding-php-code-2/#post-13798489)
 * I would suggest using [https://wordpress.org/plugins/insert-php-code-snippet/](https://wordpress.org/plugins/insert-php-code-snippet/)
   plugin.
 * If you feeel comfortable coding, you can create a child theme: [https://developer.wordpress.org/themes/advanced-topics/child-themes/](https://developer.wordpress.org/themes/advanced-topics/child-themes/)
 * Hope this helps!
 *  Thread Starter [aratc](https://wordpress.org/support/users/aratc/)
 * (@aratc)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/adding-php-code-2/#post-13798550)
 * Thank you for your reply, but I’ve already used this plugin and getting the same
   error, are there restrictions of php functions and can’t be used with wordpress?
 *  [Vlad](https://wordpress.org/support/users/vladytimy/)
 * (@vladytimy)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/adding-php-code-2/#post-13798799)
 * Maybe the error message might help you fix that error. Errors like this are logged.
   Check the error log on your server. If you can’t find the log, please contact
   your host.
 * Meantime, enable wp_debug and wp_debug_log and after an error, look at wp-content/
   debug.log to see if anything gets logged there.
 * Read more here: [https://wordpress.org/support/article/debugging-in-wordpress/](https://wordpress.org/support/article/debugging-in-wordpress/)
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/adding-php-code-2/#post-13799203)
 * Your code appears to be a complete, stand alone .php webpage which does not utilize
   any WP resources. You could put it into its own .php file and upload to your 
   server outside of WP. Link directly to the file instead of using WP permalinks.
 * In any case, the PHP output needs to occur before the closing `</body></html>`
   tags. It’s not the cause of a fatal error, but as it is, it’s invalid HTML all
   the same.
 *  [Dion](https://wordpress.org/support/users/diondesigns/)
 * (@diondesigns)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/adding-php-code-2/#post-13799692)
 * As written, your HTML code is incompatible with WordPress. But let’s assume you
   are able to rewrite the HTML to make it compatible.
 * Are the `PDO` and `PDO_mysql` extensions loaded in PHP? It makes zero sense to
   use PDO for a single, extremely-simple query, so if the extensions aren’t available,
   just use simple `mysqli_` functions.
 *  Thread Starter [aratc](https://wordpress.org/support/users/aratc/)
 * (@aratc)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/adding-php-code-2/#post-13814538)
 * [@bcworkz](https://wordpress.org/support/users/bcworkz/), Thank you for the reply.
   Do you mean uploading the file to the file manager of the cpanel? but after that
   how to include it in my page?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/adding-php-code-2/#post-13818240)
 * I don’t think you can include PHP code through Elementor. To include that file
   into a WP page, you’d need a to make a page using a [custom page template](https://developer.wordpress.org/themes/template-files-section/page-template-files/)
   which includes or requires the file. If you do that, the included file should
   not have html and body tags.
 * With that approach, upload the file (using file manager or FTP) to the WP folder
   of either a child theme or custom plugin. Or still external to WP if you prefer,
   anywhere accessible by the file system will work TBH.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Adding PHP Code’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [snippet](https://wordpress.org/support/topic-tag/snippet/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 9 replies
 * 5 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/adding-php-code-2/#post-13818240)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
