PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 7, 2022

[FIXED] MAMP unable to insert data into database with PHP

 March 07, 2022     apache, mamp, mysqli, php     No comments   

Issue

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.


Solution

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.



Answered By - Neo Wang
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing