Home > Software design >  How to Solve Problem In Post request in Phpmyadmin with flutter
How to Solve Problem In Post request in Phpmyadmin with flutter

Time:02-21

Everything is Working Fine No Error. But I don't Know Why data is not posted on my database.

I'm new TO flutter so I need these Code Using tutorials. Get Method is Working Fine but Post method not working. IN localhost code was working Now I hosted this project database on the server

This is my database File. Create.php

<?php
include "db.php";

$name = isset($_POST['name']) ? $_POST['name'] : '';
$desciption = isset($_POST['desciption']) ? $_POST['desciption'] : '';
$addr = isset($_POST['addr']) ? $_POST['addr'] : '';
$image_url = isset($_POST['image_url']) ? $_POST['image_url'] : '';
$price = isset($_POST['price']) ? $_POST['price'] : '';


$stmt = $db->prepare("INSERT INTO house (name, desciption,addr,image_url,price) VALUES (?, ?,?,?, ?)");
$result = $stmt->execute([$name, $desciption,$addr,$image_url,$price]);

echo json_encode($result);
      

When I'm Clicking on Submit Button on error get is this

Error

API response

enter image description here

I need your support. I am posting the question again because it's not been solved past 8 days

Thanks in Advance

CodePudding user response:

$stmt = $db->prepare("INSERT INTO house (name, desciption,addr,image_url,price) VALUES (?, ?,?,?, ?)"); $result = $stmt->execute([$name, $desciption,$addr,$image_url,$price]);

in this section should also bind the parameters because you are using prepared statements.

    $stmt = $db->prepare("INSERT INTO house (name, desciption,addr,image_url,price) VALUES (?, ?,?,?, ?)");
    $stmt->bind_param("sssss", $name, $desciption, $addr, $image_url, $price);
    // s means string so if the price is not string you can change it to integer (i) or double (d)
    $result = $stmt->execute();

If this does not work please change bind_param part to:

$stmt->bindParam(1, $name, PDO::PARAM_STR); 
$stmt->bindParam(2, $desciption, PDO::PARAM_STR);
$stmt->bindParam(3, $addr, PDO::PARAM_STR);
$stmt->bindParam(4, $image_url, PDO::PARAM_STR);
$stmt->bindParam(5, $name, PDO::PARAM_STR); 

And you have typo in desciption, it should be "description"

  • Related