1

I've created this PHP files that should read a python scripts with arguments and process this script.

$error = array();
$data = array();
include("./includes/common.php");

if($_SERVER["REQUEST_METHOD"] == 'POST'  && isset($_POST["submit"])){
    $lbl10 = filter_input(INPUT_POST, 'lbl10', FILTER_SANITIZE_STRING);
    $filePath = uploadFile('C:/xampp/htdocs/GraduationProject/images/test/');

    if(empty($error)){

        $output = shell_exec("C:/xampp/htdocs/GraduationProject/includes/train.py {$lbl10} {$filePath}");
        if($output){
            $ret = $db->getData("WHERE ID='{$output}'");
            while($row = $ret->fetchArray(SQLITE3_ASSOC)){
                $data = $row;
            }
        }

        $success = "Data saved successfully!";
    }
}else if($_SERVER["REQUEST_METHOD"] == 'POST'){
    $error[] = "Required Field Missing";
}

$db->close();

The PHP file should outcome some results according to the python script processing with the database after this if statement:

<?php if(!empty($data)){ ?>

But nothing happens as $data seems to be always empty.

1
  • 1
    Why not your check the $row and $data value? Commented May 29, 2017 at 13:16

1 Answer 1

1

Maybe the error is here

        while($row = $ret->fetchArray(SQLITE3_ASSOC)){
            $data = $row;
        }

because of each iteration overwrite $data value.

I think you need a different behavior. Maybe

        while($row = $ret->fetchArray(SQLITE3_ASSOC)){
            $data[] = $row;
        }

or

        while($row = $ret->fetchArray(SQLITE3_ASSOC)){
            if (null != $row) {
                $data = $row;
            }
        }
Sign up to request clarification or add additional context in comments.

1 Comment

I think, he should add while (...){ $data[] = $ret->fetchArray(...); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.