0

I am a little out of practice with my php and mysql but this particular issue has me scratching my head.

This function works fine.

 public function updateGarmentInUse($garid,$inUse){

    $stmt = $this->dbconnect->prepare('UPDATE garments SET garments.inuse = ?,
                            garments.dateupdated = CURDATE() WHERE garments.garmentid = ?');

    $stmt->bind_param("ii",$garInUsePost,$garIdPost);

    $garIdPost = $garid;
    $garInUsePost = $inUse;

    return $stmt->execute();

}

However the following function does not work.

 public function getOneGarment($garid){

    $stmt = $this->dbconnect->prepare('SELECT garments.garmentid,garments.typeid,garments.sizeid,garments.colorid,garments.timeperiodid,
                            garments.inuse,DATE_FORMAT(garments.dateentered, "%M %d %Y") AS invdate
                        FROM garments WHERE garments.garmentid = ? ');

    $stmt->bind_param("i",$garIdPost);

    $garIdPost = $garid;

    return $stmt->execute();

}

I receive Call to a member function fetch_assoc() error on my page which I assume means the query is not properly formed. In order to identify the problem I made the function to read as the following.

 public function getOneGarment($garid){

    $garIdPost = $garid;

    return $this->dbconnect->query('SELECT garments.garmentid,garments.typeid,garments.sizeid,garments.colorid,garments.timeperiodid,
                            garments.inuse,DATE_FORMAT(garments.dateentered, "%M %d %Y") AS invdate
                        FROM garments WHERE garments.garmentid ='.$garIdPost.'');

}

Since this works I assume that means the value is being passed to the function correctly so I'm at a lost.

Full error I see in my browser.

PHP Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean in C:\inetpub\wwwroot\example1\views\editGarments.php:20 Stack trace: #0 C:\inetpub\wwwroot\example1\index.php(24): include() #1 {main} thrown in C:\inetpub\wwwroot\example1\views\editGarments.php on line 20

Dharman
  • 30,962
  • 25
  • 85
  • 135
dutchlab
  • 541
  • 1
  • 13
  • 27
  • Does the first example produce an error? – Jay Blanchard Jul 07 '17 at 12:58
  • That you are Basildon Bond @RiggsFolly! – Jay Blanchard Jul 07 '17 at 12:59
  • The first example works fine with no errors and data is returned successfully. – dutchlab Jul 07 '17 at 13:02
  • 1
    Add `ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` to the top of your script. This will force any `mysqli_` errors to generate an Exception that you can see on the browser and other errors will also be visible on your browser. – RiggsFolly Jul 07 '17 at 13:02
  • 2
    Actually the First example is an UPDATE and No Data is returned from an UPDATE other then (true or false) – RiggsFolly Jul 07 '17 at 13:03
  • I really dont see why you do `$garIdPost = $garid;` instead of simply binding the parameter to `$stmt->bind_param("i",$garid);` But that is not an error, just a rather wierd kind of logic – RiggsFolly Jul 07 '17 at 13:05
  • I have reviewed my other functions and I have an insert that works and of course the update works. As far as the binding I was just following the previous patterns for consistency. – dutchlab Jul 07 '17 at 13:10
  • what error you see? – buildok Jul 07 '17 at 13:11
  • The statements that you suggested I add to the top of my script do not seem to be displaying any more info on in my browser. – dutchlab Jul 07 '17 at 13:11
  • I added the full error to the bottom of the question. – dutchlab Jul 07 '17 at 13:14
  • `$this->dbconnect->error` : does this have anything in it? – Adam Forbis Jul 07 '17 at 13:23
  • $this->dbconnect->error does not have anything. I placed is in the function before and after the execute statement and no new errors appeared. – dutchlab Jul 07 '17 at 13:32
  • Is there a reason you use variables you assign to /after/ the bind-call, instead of directly binding the method-parameters? – Tom Regner Jul 07 '17 at 13:34
  • No, I was just following an example I had laying around. – dutchlab Jul 07 '17 at 13:41
  • The problem is that you're assigning the value *after* you bind it: `$garIdPost = $garid;` - move that to *before* your `stmt->bind` line, and see what happens. – random_user_name Jul 07 '17 at 13:45
  • I moved it with no change. I even tried using the method parameter instead of assigning with the same result. – dutchlab Jul 07 '17 at 13:50
  • You dont have a `fetch_assoc()` in this code, But basically your query has failed and therefore the `execute()` has failed therefore returning FALSE and not a MYSQLI::STMT Object to whereever you ARE running a `fetch_assoc()` – RiggsFolly Jul 07 '17 at 13:54

0 Answers0