Jump to content

Fatal Error when trying to execute simple SELECT query


cr0ck3t

Recommended Posts

I am trying to run the following:

$sqlErrors = "";

$query = "SELECT `name` FROM company WHERE id=".$_POST['companyID'];
$result = $mysqli->query($query);
$row = $result->fetch_assoc();
$company = $row['name'];

$sqlErrors = $mysqli->error ? "Selecting company, id: ".$_POST['companyID'].". Error: ".$mysqli->error : "";

And am getting the following output:

Fatal error: Call to undefined method mysqli::SELECT `name` FROM company WHERE id=3() 

I have no idea where the trailing brackets are coming from, and even tried

$result = $mysqli->query("SELECT `name` FROM company WHERE id=3");

... but get the same result.

 

 

The questionable piece of code is contained within the following, in the "what company are we regestering the agent to?" section.

$all_query_ok = true;
        $sqlErrors = "";
        /* connect to the db */
        $mysqli = new mysqli('localhost','riski296_dbuser','7FJTCJyMARer90oCKmyek5Cw36wXYG1etWJcOGjYONn53liYEHkTb0v74WqpVV3O', 'riski296_taxi_pim') or die('Cannot select the DB');
        
        /*
         * what company are we regestering the agent to?
         */
        $query = "SELECT `name` FROM company WHERE id=".$_POST['companyID'];
        $result = $mysqli->query($query);
        $row = $result->fetch_assoc();
        $company = $row['name'];
        
        $sqlErrors = $mysqli->error ? "Selecting company, id: ".$_POST['companyID'].". Error: ".$mysqli->error : "";

        /* grab the first available agnet for that company */
        $agentID = -1;
        if ($result = $mysqli->query("SELECT id FROM agent WHERE is_active=0 AND companyID=".$_POST['companyID']." LIMIT 1")) {
            if($result->num_rows == 1){
                /* fetch object array */
                $row = $result->fetch_assoc();
                $agentID = $row['id'];
            } else {
                echo "There is no agents currently entered for ".$company;
                exit();
            }
            $sqlErrors .= $mysqli->error ? ".  Getting agent, company id: ".$_POST['companyID'].". Error: ".$mysqli->error : "";
        }
        
        /* determine what kind of connection device is being used */
        $connectionDeviceID = -1;
        switch($_POST['connectionDeviceType']) {
            case "Cellular":
                $connectionDeviceID = $_POST['cellularConnectionDeviceID'];
                break;
            case "LAN":
                $connectionDeviceID = $_POST['lanConnectionDeviceID'];
                break;
        }
        $mysqli->autocommit(FALSE);
        
        /*
         * INSERT connection device being used with this PIM
         */
        $mysqli->$query("    INSERT INTO connection_device (idDevices, device_type, idPlan)
                            VALUES (".$connectionDeviceID.",
                                    ".$_POST['connectionDeviceType'].",
                                    ".$_POST['planID'].")") ? null : $all_query_ok = false;
        $sqlErrors .= $mysqli->error ? ".  Inserting connection_device, connection device id: ".$connectionDeviceID.", Connection device type: ".$_POST['connectionDeviceType'].", and Plan ID: ".$_POST['planID'].". Error: ".$mysqli->error : "";
        
        /*
         * INSERT PIM and associate the connection device with the PIM
         */
        $mysqli->$query("    INSERT INTO device (idDevices, idAgent, idConnectionDevice)
                            VALUES (".$_POST['pimID'].",
                                    NULL,
                                    ".$mysqli->insert_id.")") ? null : $all_query_ok = false;
        $sqlErrors .= $mysqli->error ? ".  Inserting PIM, PIM id: ".$_POST['pimID'].", agent ID: NULL, and Plan ID: ".$_POST['planID'].". Error: ".$mysqli->error : "";
        
        /*
         * associate the device with the company.  make note of install date
         */
        $install_date = date("Y-m-d H:i:s");
        $mysqli->$query("    INSERT INTO compay_device_relation (idCompany, idDevice, install_date, location, removal_date)
                            VALUES (".$_POST['companyID'].",
                                    ".$mysqli->insert_id.",
                                    ".$install_date.",
                                    NULL,
                                    NULL)") ? null : $all_query_ok = false;
        $sqlErrors .= $mysqli->error ? ".  Inserting company_device_relation, idCompany: ".$_POST['companyID'].", idDevice: ".$mysqli->insert_id.", install_date: ".$install_date.", location: NULL, and removal_date: NULL. Error: ".$mysqli->error : "";
        
        /*
         * check for any pre-existing errors
         */
        if($sqlErrors != "") {
            echo $sqlErrors;
            exit();
        }
        
        /*
         * update agent - this makes sure that the agent is still available
         */
        $mysqli->query("UPDATE agent SET is_active=1 WHERE id=".$agentID) ? null : $all_query_ok = false;
        $mysqli->affected_rows == 1 ? null : $all_query_ok = false;
        $all_query_ok ? $mysqli->commit() : $mysqli->rollback();
        $mysqli->autocommit(TRUE);
        $mysqli->close();
        echo $all_query_ok ? "Agent added to ".$company : "failure:";

Any help is most appreciated!

 

Thanks,

Dave.

 

        $mysqli->$query("    INSERT INTO connection_device (idDevices, device_type, idPlan)

//...
        $mysqli->$query("    INSERT INTO device (idDevices, idAgent, idConnectionDevice)
//...
        $mysqli->$query("    INSERT INTO compay_device_relation (idCompany, idDevice, install_date, location, removal_date)

 

You got a little $ happy there. Too many of them.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.