Coder Social home page Coder Social logo

Comments (13)

clh021 avatar clh021 commented on May 16, 2024 1

Hey! @kimeeo What wrong? Me too.

@mevdschee Maybe this tool should write some log or debug.
return null. And no more .I 'm cray......

curl -X POST "http://localhost/api.php/posts" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"user_id\": 44, \"category_id\": 3, \"content\": \"这是一个测试\"}"

Code | Details
--       |   --
200 | Response body     null
         Response headers content-type: application/json; charset=utf-8


Code | Description
-- | --
200 | Identifier of created item.
Example Value
Model   0


Sorry..................

user_id and category_id must be exist.

from php-crud-api.

mevdschee avatar mevdschee commented on May 16, 2024 1

@xouaib it is probably another exception, please replace "PDOException" with "Exception" or "Throwable" depending on your PHP version.

from php-crud-api.

mevdschee avatar mevdschee commented on May 16, 2024 1

@xouaib You are now sending post parameters and expect it to be a JSON document, that's not correct.

from php-crud-api.

kimeeo avatar kimeeo commented on May 16, 2024

Try this with

PUT http://kimeeo.com/restDemo/api.php/categories/2
name=my_name

POST
http://kimeeo.com/restDemo/api.php/categories
name=my_name

DELETE
http://kimeeo.com/restDemo/api.php/categories/2

all it does is return null.

from php-crud-api.

mevdschee avatar mevdschee commented on May 16, 2024

I would love to help, but I need more information. Which database engine do you use? Which SQL file did you load? What platform are you on? Which client do you use (like PostMan or curl)? Please provide more information.

from php-crud-api.

mevdschee avatar mevdschee commented on May 16, 2024

Went to "http://editor.swagger.io/" and clicked "File" - "Import URL" and entered "http://kimeeo.com/restDemo/api.php". There I tested your API and it works fine!

from php-crud-api.

kimeeo avatar kimeeo commented on May 16, 2024

Which database engine do you use.
-> MySQL

Which SQL file did you load
->blog_mysql.sql

What platform are you on?
-> PHP 5.6

Which client do you use
-> PostMan

As I said, GET is working

but if PUT, DELETE, POST it reutnr's null

from php-crud-api.

kimeeo avatar kimeeo commented on May 16, 2024

My Bad, Something was wrong at my end.

from php-crud-api.

mevdschee avatar mevdschee commented on May 16, 2024

No problem, enjoy the software!

from php-crud-api.

mevdschee avatar mevdschee commented on May 16, 2024

I don't know, probably returning an header with the error message would make most sense.. but only in the case some debug flag is true.. for security reasons.. or yes.. logging.. that could also work..

from php-crud-api.

xouaib avatar xouaib commented on May 16, 2024

@mevdschee hi dear,
pl i create CRUD system API using PHP and MySQL, then the POST not working :

<?php
include 'config/database.php';
if ($_POST) {

    try {

        $query = "INSERT INTO products SET p_name=:name, p_description=:description, p_price=:price";

        $stmt = $con->prepare($query);

        $name = $_POST['name'];
        $description = $_POST['description'];
        $price = $_POST['price'];

        $stmt->bindParam(':name', $name);
        $stmt->bindParam(':description', $description);
        $stmt->bindParam(':price', $price);

        if ($stmt->execute()) {
            echo json_encode(array('result' => 'success'));
        } else {
            echo json_encode(array('result' => 'fail'));
        }
    } catch (PDOException $exception) {
        die('ERROR: ' . $exception->getMessage());
    }
}

the database file contains already all header that we need , i check the CREATE with POST method using POSTMAN but not working

image

CORDIALLY
CORD

from php-crud-api.

xouaib avatar xouaib commented on May 16, 2024

i still strive with it without ay advance Mr @mevdschee
1
2

from php-crud-api.

xouaib avatar xouaib commented on May 16, 2024

@mevdschee thank you so much it's working perfectly

from php-crud-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.