2016-04-27 11 views
0

Der Versuch, in Repot_comments Tabelle einfügen in report_comment Tabelle ReportID und KommentareKommentar einfügen verknüpft schreiben ID

Allerdings bekomme ich jetzt Fehler

Error Number: 1064 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0) VALUES ('Report_Comments')' at line 1 

INSERT INTO `Report_Comments` (0) VALUES ('Report_Comments') 

Filename: models/report/Report_model.php 

Line Number: 61 

-Controller

function comment_add() 
     { 
       if ($query = $this->report_model->create_comment()) { 

        $this->session->set_flashdata('messagetwo', 'You added a Comment'); 
        redirect('main/comments/' .$_POST['ReportID']); 

       } else { 
        $this->session->set_flashdata('messagetwo', 'Sorry not this time'); 
        redirect('main/comments/' .$_POST['ReportID']); 
       } 
     } 

Modell

function create_comment() 
{ 

    $new_comment = array(
     'Comments', $_POST => $this->input->post('Report_Comments') 
    ); 

    $insert = $this->db->insert('Report_Comments', $new_comment); 
    return $insert; 
} 

Ansicht

<p><?= anchor('main', 'Back home'); ?></p> 

    <?= form_open('main/comment_add'); ?> 

    <?= form_hidden('ReportID', $this->uri->segment(3)); ?> 

    <p><textarea name="Comments" rows="10"></textarea></p> 
    <p><input type="submit" value="add comment"/></p> 

    <?php 
    if ($this->session->flashdata('messagetwo')) { 
     ?> 
     <div class="message flash"> 
      <?php echo $this->session->flashdata('messagetwo'); ?> 
     </div> 
     <?php 
    } 
    ?> 

    </form> 
+0

Das Duplikat gilt auch für Spaltennamen. –

+0

Es ist kein Duplikat, ich habe die alte Frage gelöscht, weil ich dachte, dass es keinen Sinn ergibt und ein Durcheinander war. Ich habe die Frage neu geschrieben und den Code geändert. – Beep

+0

'richtige Syntax zu verwenden in der Nähe von '0)' und und Ihre Abfrage ist das '(0) VALUES (' Report_Comments ')', daher ist es ein Duplikat. –

Antwort

0

Das Problem ist Sie:

$new_comment = array(
     'Comments', $_POST => $this->input->post('Report_Comments') 
    ); 

prüft mit einem var_dump($new_comment), sollte der erste Index 0 sein;

Versuchen Sie das mal:

$new_comment = array(
     'Comments' => $this->input->post('Report_Comments') 
    ); 

Angenommen, Ihr Feld "Kommentare" und $this->input->post('Report_Comments') eine gültige Zeichenfolge zurück.

Here is the documentation of $this->db->insert() for codeigniter

+0

das ist der Fehler, wie würde ich das im Code tun? – Beep

+1

Ich habe meine Antwort bearbeitet, ich hoffe, dass dir das weiterhilft. –

Verwandte Themen