Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 2878
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 1, 20222022-06-01T17:20:03+00:00 2022-06-01T17:20:03+00:00

php – Getting Uncaught mysqli_sql_exception in my project

  • 0

[ad_1]

I am learning how to make android app.
I am getting “Uncaught mysqli_sql_exception: You have an error in your SQL syntax;” error. since I am new to php and database I am not able to reslove the issue. I hope you guys will help me.
I am providing everystuff to seek better help.

Mysql database: Database Image

The error: Error in postman

I am getting error in this part of code:

if($request->{'action'} == 'ADD_NEWS'){
        $isValidRequest = true;

        $headline = $request -> {'headline'};
        $description = $request -> {'description'};
        $userId = $request -> {'userId'};

        $query = "INSERT INTO news('headline','description','user_id') VALUES ('".$headline."','".$description."','".$userId."')";
        $result = mysqli_query($connection,$query);
        if($result){
            $response['newsId'] = mysqli_insert_id($connection);
            $response['status'] = true; 
            $response['responseCode'] = 0; //News Added Successfully
            $response['message'] = "News Added Successfully";               
        }else{
            $response['status'] = false; 
            $response['responseCode'] = 102; //News not added
            $response['message'] = "News Not Added";
        }

The line i am getting error in is: $result = mysqli_query($connection,$query);

The whole code:

<?php

include 'config/db_config.php';

$data = file_get_contents("php://input");
$request = json_decode($data);
$response = array();
$isValidRequest = false;

//{"action":"REGISTER_USER","userName":"Mr. Amir"}
//REGISTER_USER
//ADD_NEWS
//GET_NEWS
//UPDATE_NEWS
//DELETE_NEWS

if(isset($request->{'action'})){
    if($request->{'action'} == 'REGISTER_USER'){
        $isValidRequest = true;
        $userName = $request -> {'userName'};

        $query = "INSERT INTO user(name) values('".$userName."')";
        $result = mysqli_query($connection,$query);
        if($result){
            $response['userId'] = mysqli_insert_id($connection);
            $response['status'] = true; 
            $response['responseCode'] = 0; //User Registered Successfully
            $response['message'] = "User Registered Successfully";              
        }else{
            $response['status'] = false; 
            $response['responseCode'] = 102; //User Registered Failed
            $response['message'] = "User Registered Failed";                
        }
    }

    if($request->{'action'} == 'ADD_NEWS'){
        $isValidRequest = true;

        $headline = $request -> {'headline'};
        $description = $request -> {'description'};
        $userId = $request -> {'userId'};

        $query = "INSERT INTO news('headline','description','user_id') VALUES ('".$headline."','".$description."','".$userId."')";
        $result = mysqli_query($connection,$query);
        if($result){
            $response['newsId'] = mysqli_insert_id($connection);
            $response['status'] = true; 
            $response['responseCode'] = 0; //News Added Successfully
            $response['message'] = "News Added Successfully";               
        }else{
            $response['status'] = false; 
            $response['responseCode'] = 102; //News not added
            $response['message'] = "News Not Added";
        }
    }

    if($request->{'action'} == 'GET_NEWS'){
        $isValidRequest = true;
    }

    if($request->{'action'} == 'UPDATE_NEWS'){
        $isValidRequest = true;
    }

    if($request->{'action'} == 'DELETE_NEWS'){
        $isValidRequest = true;
    }

    if(!$isValidRequest){
        $response['status'] = false; 
        $response['responseCode'] = 100; //Invalid request action
        $response['message'] = "Invalid request action";
    }
}else{
    $response['status'] = false; 
    $response['responseCode'] = 100; //Request action not defined
    $response['message'] = "Request action not defined";
}

echo json_encode($response);

?>

[ad_2]

  • 0 0 Answers
  • 4 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 2 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 4 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 3 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.