PHP REST API From Scratch [2] - Single & Create

PHP REST API From Scratch [2] - Single & Create

Traversy Media

6 лет назад

147,010 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Gowner Jones
Gowner Jones - 11.02.2023 22:33

Is there a reason why you used print_r() instead of echo?

Ответить
Mahfoud
Mahfoud - 27.09.2022 11:14

Hello, everything works well except the writing in the database, it puts + between each word (instead of space) Thank you

Ответить
A 1 App Builders
A 1 App Builders - 16.08.2022 09:04

Has the area been abandoned?????

Ответить
A 1 App Builders
A 1 App Builders - 25.06.2022 05:29

Hi just tried ur instruction and code today 6-24-2022 it worked great. would it be a lot of trouble to use/add the ability for a api key that i assign to him and her etc.

Ответить
John Lyons
John Lyons - 14.06.2022 00:20

Hey Brad. Love your videos. However, I have this weird error on postman where it says

"Header may not contain more than as ingle header, new line detected in
:\XAMPP\htdocs\php_rest_myblog\api\post\create.php</b> on line <b>6</b><br />

And then on each value I get 4 individual errrors stating
<b>Warning</b>: Attempt to read property "title" on null in <b>C:\XAMPP\htdocs\php_rest_myblog\api\post\create.php</b>
on line <b>24</b><br />

Has anyone else had these issues? Or is it just a hard bug?

Ответить
Roberto B
Roberto B - 13.04.2022 20:01

Hi, If you return the variable $row, and do echo json_encode($row) you obtain the same result. Is it really useful do it in your way?

Ответить
Kristaps
Kristaps - 26.11.2021 14:39

Really great stuff! Just finished building API for a client that sends Woocommerce orders to their CMR. Before these 2 tutorials, I had no idea how to do that :). Of course a ton of StackOverflow reading was involved, but fundament came from here. Thank you very much for your great work!

Ответить
Setiawan
Setiawan - 26.11.2021 05:33

how to solve this problem ? PHP Notice: Trying to get property 'title' of non-object

Ответить
Alexander Smidt
Alexander Smidt - 02.11.2021 04:26

its active record?

Ответить
Deva Gunalan
Deva Gunalan - 14.07.2021 05:14

Hi Brad.. first let me mention that your tutorial illustrations are nothing short of AWESOME!!!!.. You rock!!..
Now I followed step by step but got stuck at $stmt->execute(). I have tried different techniques to catch the error num but to no avail. I am really lost.
If any of you have similar experiences please share what you did to overcome it please. Thank you.

Ответить
Abd Qz
Abd Qz - 08.06.2021 20:00

like read in independent file like other methods, is it necessary ?

Ответить
Abd Qz
Abd Qz - 08.06.2021 20:00

so, from the full angel view, the api files are just like the normal files but the diff only overwrite the methods written in the original files in modules ?

Ответить
Cube Dev
Cube Dev - 22.04.2021 03:05

Hello brad, can u continue this series by implementing token, so only certain people that have token only can access this api...

Ответить
Rob Hills
Rob Hills - 26.02.2021 20:51

If like me you are finicky about stuff, with the read_single function in the Post.php class you can add some code to stop the output of null JSON for when a user enters an ID that is not in the database (this may not be the best solution but it works when testing using Postman, alternatively it could be handled in the frontend I suppose) -

if(!$row) {
echo 'ID not found';
exit();
} else {
$this->title = $row['title'];
$this->body = $row['body'];
$this->author = $row['author'];
$this->category_id = $row['category_id'];
$this->category_name = $row['category_name'];
}

Ответить
toannew
toannew - 20.02.2021 16:27

thanks

Ответить
Tadej Keblič
Tadej Keblič - 07.02.2021 11:28

I have been looking for this for a long time!!! Thank you so much!!
@everbody has anyone succeeded in transforming this from single post row to mulitple post row? i belive i need to modify the create.php code after $data variable gets populated with json_decode ... Everything after that line needs to be somehow wrapped into foreach or something :D

regards

Ответить
Ujjwal Raijada
Ujjwal Raijada - 15.01.2021 12:35

Hi, can you please guide how can we upload image? Thanks.

Ответить
sfan997
sfan997 - 22.12.2020 09:07

Thank you very much!!!!

Ответить
Sell_Me_A_Waffle
Sell_Me_A_Waffle - 19.11.2020 23:29

A bit of an older video but can you explain why youre encoding the input before its indexed in the db? I noticed in the first video you also decoded this information to read it. I think it is best to leave inputs structured how they were entered for storing in the db since they will have no affect on the db. That also allows the input to be used elsewhere (if needed) more easily.

Ответить