Start New Discussion within our Web Development Community

I tested and successfully used this SQL code below to input data into a database.

    INSERT INTO hraps (id, firstname, lastname, gender, year_of_1st_rappel, count_offset_proficiency, count_offset_operational, spotter) values(111111, 'World', 'Hello', 'Male', '2007', '1', '2', '0')

Now I'm trying to integrate it into PHP like this:

     $query = "INSERT INTO hraps (firstname, lastname, gender, year_of_1st_rappel, count_offset_proficiency, count_offset_operational, spotter) "
    ."values('".$this->firstname."','".$this->lastname."','".$this->gender."','".$this->year_of_1st_rappel."',".$this->count_offset_proficiency.",".$this->count_offset_operational.",".$this->spotter.") returning id into :id";

    $dbid = "";
    $binds = array();
    $binds[] = array("name" => ":id", "value" => &$dbid, "length" => 128);
    //echo $query;              
    $result = mydb::cxn()->query($query, $binds);
    $this->id = $dbid;

But nothing gets inserted and I'm not getting any error. The only difference is that in this one I'm defining id as $dbid, and before I hard-coded it in the "values" section of the query.

Can somebody please point out why this code is not working successfully?
Thank you.

But nothing gets inserted and I'm not getting any error. The only difference is that in this one I'm defining id as $dbid, and before I hard-coded it in the "values" section of the query.

That's not how you INSERT in PHP.

Read this and look closely how to INSERT statement should look like:

http://www.phpeasystep.com/mysql/5.html

I think the problem is with returning into. Isn't this an Oracle specific construct? Anyway, I am not convinced that you can bind a return value.

I think the trouble lies with this section:

$dbid = "";
$binds = array();
$binds[] = array("name" => ":id", "value" => &$dbid, "length" => 128);

I'm not entirely sure how it's setting the id, to be honest.

This article has been dead for over six months. Start a new discussion instead.