clairett09
clairett09

Reputation: 13

MAMP unable to insert data into database with PHP

I've been struggling with this problem for a really long time. The phpmyadmin of MAMP doesn't allow me to insert data into database with php. I use object oriented style mysqli, which works as following:

    $sql = "INSERT INTO data(dataid, pic, sen)
            VALUES('$i', '$pic', '$sen')";
    if ($conn->query($sql)) {
        echo  "success<br >";
    } else {
        echo "failure<br >" . $conn->error;
    }

I got "success" as the returning message but nothing is inserted into DB. As for the SQL, I've checked with database and it is correct.

I guess the problem is about privileges but I'm the root user. Overall, I can read data from DB with PHP but can't write any to it. Does anyone know the answer to the problem?

I really appreciate your help and effort.

Upvotes: 1

Views: 1079

Answers (1)

Neo Wang
Neo Wang

Reputation: 26

How did you connect to the database? If you are using the mysqli_real_connect() as officially recommended, you could try just use mysqli($host, $user, $password, $db, $port) instead. Worked for me.

Upvotes: 1

Related Questions