0

I have insert function, this function works fine in other page. It's really weird that when try to debug it I found out that there's a weird big enter space beside the INSERT

Like this

"

INSERT INTO table (`sample`) values ("sample")" 

Other pages are working fine without enter space

"INSERT INTO table (`sample`) values ("sample")" 

here's my function

function insertData($table_name = '', $postedData = array(), $header = '',
                    $debug = TRUE)
{
    $keys = '';
    $values = '';
    if(!$table_name || !$postedData) {
        exit('missing parameter');
    }
    if(count($postedData)) {
        unset($postedData['insert']);
        $sql = "INSERT INTO $table_name " . $this->arrayToQueryString($postedData);

        if($debug) {
            exit($sql);
        }

        $statement = $this->connection->prepare($sql);

        if($statement->execute()) {
            if($header != 'login') {
                header('Location: ' . $header);

                return TRUE;
            }
        }
    }
    return FALSE;
}

Thanks works fine in my Localhost but when I transferred it in cpanel server got this problem

aynber
  • 22,380
  • 8
  • 50
  • 63
  • 1
    Spaces shouldn't make. difference. What's the exact problem you're having? – aynber Aug 06 '19 at 18:13
  • It doesn't INSERT while the other page is working fine, I tried two variables only to check if there's a problem in my form still didn't work. – Christian Read Aug 06 '19 at 18:15
  • 4
    That most likely is not your issue. Instead of just returning true/false, try checking for errors. You don't specify if you're using mysqli or PDO, but check these links: [mysqli errors](http://php.net/manual/en/mysqli.error.php) or [My PDO statement doesn't work](https://stackoverflow.com/questions/32648371/my-pdo-statement-doesnt-work). This will tell you **why** your insert is failing. – aynber Aug 06 '19 at 18:18
  • Alright I'll try it thank you – Christian Read Aug 06 '19 at 18:29
  • : "It looks like you're writing your own ORM. Have you considered using one that's already written, tested, and widely supported like [RedBeanPHP](https://redbeanphp.com/), [Doctrine](http://www.doctrine-project.org/), [Propel](http://propelorm.org/) or [Eloquent](https://laravel.com/docs/master/eloquent)?" – tadman Aug 06 '19 at 19:07

0 Answers0