2017-03-18 2 views
-1

Hallo, wie zum Aktualisieren der aktive Spalte in der Tabelle scheint nicht mein Codewie die aktiven Spalt

db.php `öffentliche Funktion aktiv ($ table, $ id, $ Felder, $ activecode) arbeiten zu aktualisieren { $ set = ''; $ x = 1;

 foreach($fields as $name => $value){ 
      $set .= "{$name} = ?"; 
      if($x < count($fields)) { 
       $set .= ', '; 
      } 
      $x++; 
     } 

     $sql = "UPDATE {$table} SET {$set} WHERE id = {$id} AND activecode = {$activecode}"; 

     if(!$this->query($sql, $fields)->error()){ 
      return true; 
     } 

     //return false; 
    }` 

activate.php

`require_once 'Kern/init.php';

if(Input::exists()){ 

if(Token::check(Input::get('token'))){ 

     $validate = new Validate(); 
     $validation = $validate->check($_POST, array(
      'id' => array('required' => 'true'), 
      'activecode' => array('required' => 'true') 

     )); 

     if($validation->passed()){ 
      $user = new User(); 

       $user->active(array(

        'active'  => 1 
       )); 

       Session::flash('success', 'success.'); 
       Redirect::to('index.php'); 
      }else{ 

       echo "error"; 
      } 
     }else{ 
      pre($validation->errors()); 
     } 


    }` 

Aktivierungslink Activate.php? Aktiv =. $ Activecode. . & id = $ id

Antwort

0
$set .= "{$name} = '{$value}'"; 

auch "$ this" muss ein mysqli-Objekt sein und das Format ist:

$mysqli = new mysqli("localhost", "my_user", "my_password", "world"); 
$mysqli->query($sql); 
if(!$mysqli->error){ 

mysqli::query

+0

funktioniert nicht! php CURD ist ein Denksport lol – sami

+0

wenn Sie $ sql Echo, was ist die Ausgabe? –

+0

hier ist der vollständige Code DB.php => https://codepad.remoteinterview.io/playback/XWOYTUNPPQ init.php => https://codepad.remoteinterview.io/playback/UODTAEPFNH activate.php => https://codepad.remoteinterview.io/playback/XXTXERDRDZ danke für deine Antwort @Chad Skiles – sami