Title: Need help with databases in plugin development.
Last modified: August 31, 2016

---

# Need help with databases in plugin development.

 *  [dsman](https://wordpress.org/support/users/dsman/)
 * (@dsman)
 * [10 years ago](https://wordpress.org/support/topic/need-help-with-databases-in-plugin-development/)
 * Hello,
    I’m developing rating plugin for school project and I can’t figure it
   out how to properly connect and store data in database.
 * May you help me with providing some good tutorials suitable for beginners?
 * Right now I’m trying this way, which doesn’t work and as far as I know it’s wrong
   for WordPress.
 *     ```
       ?php
       $ipaddress = md5($_SERVER['REMOTE_ADDR']); // here I am taking IP as UniqueID but you can have user_id from Database or SESSION
   
       $servername = "localhost"; // Server details
       $username = "root";
       $password = "";
       $dbname = "events";
   
       $conn = new mysqli($servername, $username, $password, $dbname);
       if ($conn->connect_error) {
           die("Unable to connect Server: " . $conn->connect_error);
       }
   
       if (isset($_POST['rate']) && !empty($_POST['rate'])) {
   
           $rate = $conn->real_escape_string($_POST['rate']);
       // check if user has already rated
           $sql = "SELECT <code>id</code> FROM <code>tbl_rating</code> WHERE <code>user_id</code>='" . $ipaddress . "'";
           $result = $conn->query($sql);
           $row = $result->fetch_assoc();
           if ($result->num_rows > 0) {
               echo $row['id'];
           } else {
   
               $sql = "INSERT INTO <code>tbl_rating</code> ( <code>rate</code>, <code>user_id</code>) VALUES ('" . $rate . "', '" . $ipaddress . "'); ";
               if (mysqli_query($conn, $sql)) {
                   echo "0";
               }
           }
       }
       $conn->close();
       ?>
       ```
   
 * Thank you!

The topic ‘Need help with databases in plugin development.’ is closed to new replies.

## Tags

 * [beginner](https://wordpress.org/support/topic-tag/beginner/)
 * [database](https://wordpress.org/support/topic-tag/database/)
 * [development](https://wordpress.org/support/topic-tag/development/)
 * [tutorial](https://wordpress.org/support/topic-tag/tutorial/)

 * 0 replies
 * 1 participant
 * Last reply from: [dsman](https://wordpress.org/support/users/dsman/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/need-help-with-databases-in-plugin-development/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
