Title: adding mysql record inside post
Last modified: August 20, 2016

---

# adding mysql record inside post

 *  [ukndoit](https://wordpress.org/support/users/ukndoit/)
 * (@ukndoit)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/adding-mysql-record-inside-post/)
 * I have installed a php plugin that allows me to execute php inside a plugin when
   I put php tags around it…
 * I am successfully able to add code, but when I try to do this:
 *     ```
       [php]
   
       	$link = mysql_connect('localhost', 'dt_wp791', 'MpX7b4zL81');
       	if (!$link) {
       		die('Could not connect: ' . mysql_error());
       	}
       	mysql_select_db('dt_wp858');
       	mysql_query('INSERT INTO <code>dt_wp858</code>.<code>cbpr</code> (<code>cbprid</code>, <code>key</code>, <code>rcpt</code>, <code>time</code>, <code>item</code>, <code>cbpop</code>, <code>cemail</code>) VALUES (NULL, "'.$key.'", "'.$rcpt.'", "'.$_time.'", "'.$item.'", "'.$cbpop.'", "'.$cemail.'")');
       [/php]
       ```
   
 * nothing happens, I don’t even see an error.
    How do I make this work? any ideas?
   thank you, Richard

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

 *  [360](https://wordpress.org/support/users/360gradfoto/)
 * (@360gradfoto)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/adding-mysql-record-inside-post/#post-3209008)
 * Hi Richard,
    you are executing php in a shortcode from the wp editor. This often
   leads to messed up source codes. those `...` parts are breaking the sql input.
 * a better option is phpmyadmin.
    Check with your webhost/cpanel if you can get
   access to it and insert the database input through the phpmyadmin interface. 
   hope this helps 🙂
 * btw: do not post your sql username and password 😉 you should edit your code 
   above.
 *  Thread Starter [ukndoit](https://wordpress.org/support/users/ukndoit/)
 * (@ukndoit)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/adding-mysql-record-inside-post/#post-3209017)
 * those are not the real connections… I changed them just to show the sample of
   code…
 * also, I cannot use phpmyadmin, since the code is what needs to execute when someone
   buys an ebook on clickbank… I am trying to add the purchase to the database, 
   to help with customer service…
 * Since the download page has the receipt on it and it verifies it or does not 
   deliver the download page. So I want to store it so they can retrieve the download
   link automatically if they did not download it and all the bonuses when they 
   were first taken there. To help limit how much need they will have for customer
   service and make it easier for them to help themselves.
 * I don’t think any of the code is breaking, when I put something that fails the
   webpage shows the php code instead of the stuff printed with echo on the page…
   
   And with the above code it executes fine, no errors or anything.
 * So I don’t know why it won’t work.
    That is why I am asking here in case anyone
   else has the same problem. Thank you, Richard
 *  Thread Starter [ukndoit](https://wordpress.org/support/users/ukndoit/)
 * (@ukndoit)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/adding-mysql-record-inside-post/#post-3209020)
 * omg, I read what you said closely, I see what you are talking about now…
    you
   are saying it is best to add the php in the phpmyadmin instead of the wp editor…
 * duh… oh boy.
    I will try it. Thank you.
 *  [360](https://wordpress.org/support/users/360gradfoto/)
 * (@360gradfoto)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/adding-mysql-record-inside-post/#post-3209024)
 * phpmyadmin is for sql database handling. It´s not intended to execute php.
 * But you can try to create a function in your theme’s functions.php which takes
   care of the database input.
 *  Thread Starter [ukndoit](https://wordpress.org/support/users/ukndoit/)
 * (@ukndoit)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/adding-mysql-record-inside-post/#post-3209035)
 * Ok, I created the code in a PHP file, then in the functions.php theme file, I
   created a require_once to pull it in…
 * that works, but it still does not write anything to the database.
 * does the mysql_query() not work in wordpress? I am assuming that already has 
   a mysql connection since it is pulling out of the same database I created that
   table in.
 * Can someone tell me what I have to do to make it work?
    Thank you Richard
 *  Thread Starter [ukndoit](https://wordpress.org/support/users/ukndoit/)
 * (@ukndoit)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/adding-mysql-record-inside-post/#post-3209079)
 * Wow, I cannot get this to work no matter what I do…
 * Where can I find some mysql code in the wordpress site files, so that I can copy
   the code and modify it.
 * Please let me know.
    Thank you everyone for any help you can be. Richard
 *  [360](https://wordpress.org/support/users/360gradfoto/)
 * (@360gradfoto)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/adding-mysql-record-inside-post/#post-3209095)
 * maby this is helpful:
    [http://stackoverflow.com/questions/1670838/inserting-a-post-in-wordpress-using-mysql](http://stackoverflow.com/questions/1670838/inserting-a-post-in-wordpress-using-mysql)
 * [http://codex.wordpress.org/Function_Reference/wp_insert_post](http://codex.wordpress.org/Function_Reference/wp_insert_post)

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

The topic ‘adding mysql record inside post’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 2 participants
 * Last reply from: [360](https://wordpress.org/support/users/360gradfoto/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/adding-mysql-record-inside-post/#post-3209095)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
