-4

I have a problem on data INSERT, when I fill all rows I don't find them on my DataBase.

Here is my code:

<?php

    include("/config/config.php");

           ///////////////////////////////traitment de la requete de selection  /////////////////////////////////////

       if(isset($_POST['val']))

       {
    echo "départ";
        $imm=$_POST[im];
        $doss=$_POST[nd];
        $ass=$_POST[ns]; 
        $bn=$_POST[bn];
        $trec=$_POST[T_rec];
        $Erec=$_POST[e_rec];
        $mt=$_POST[Mt];
        $Drec=$_POST[Dt];
        $INP=$_POST[inp];
        $com=$_POST[comm];

        $resultat=mysql_query("INSERT INTO rec_info ('imma','INP','n_dossier','nom_benif','nom_ass','montant','type_rec',
        'date_rec','etat_rec','comm_rec','num_rec') Values
         ('$imm','$INP','$doss','$bn','$ass','$mt','$trec','$Drec','$Erec','$comm','')");

        if($resultat)
        {

            echo "opération réussie ";
        }else {
            echo "opération non réussie ";
        }

       }
    ?>


 </div>

<div style=" position:absolute;left:15px;width:310px;top:173px; background-color:#eff5f7; font-size:102%; padding:0em;line-height:200% ">
         Menu  
    <nav>
      <ul id="menu">
        <li><a href="rec_recherche.php">Recherche d'une réclamation PEC </a></li>
        <li><a href="s_rec.php">Saisir une réclamation PEC </a></li>
        <li><a href="">Changement d'état d'une réclamation PEC</a></li>
        <li><a href="index1.php">Quitter</a></li>

      </ul>
    </nav>

      </div>
</div> 

  </body>
</html>

Thank you

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
H-sakout
  • 3
  • 2
  • 5
    "Can you find the bug" questions [are not good questions for Stack Overflow](http://meta.stackoverflow.com/questions/253787/are-there-legitimate-fix-my-code-questions?cb=1#253788). Make sure you a brief, but **specific statement of the problem**, telling us precisely what is wrong. "It doesn't work" is not a problem statement. – John Conde May 22 '14 at 00:11
  • When you do INSERT INTO, your columns do not use quotes. Either take them out or replace them with backticks. Only the VALUES use single quotes. You also need to use quotes inside `$imm=$_POST[im];` as in `$imm=$_POST['im'];` etc. – Funk Forty Niner May 22 '14 at 00:16
  • Add error reporting to the top of your file(s) `error_reporting(E_ALL); ini_set('display_errors', 1);` during development. – Funk Forty Niner May 22 '14 at 00:20

3 Answers3

0

You cannot have single quotes around your column identifiers. Either use ticks or nothing at all:

$resultat=mysql_query("INSERT INTO rec_info (imma,INP,n_dossier,nom_benif,nom_ass,montant,type_rec,
    date_rec,etat_rec,comm_rec,num_rec) Values
     ('$imm','$INP','$doss','$bn','$ass','$mt','$trec','$Drec','$Erec','$comm','')");

or

$resultat=mysql_query("INSERT INTO rec_info (`imma`,`INP`,`n_dossier`,`nom_benif`,`nom_ass`,
`montant`,`type_rec`,`date_rec`,`etat_rec`,`comm_rec`,`num_rec) 
Values ('$imm','$INP','$doss','$bn','$ass','$mt','$trec','$Drec','$Erec','$comm','')");

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

You are also wide open to SQL injections

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • Why are you posting an answer when you are also voting to close? – jeroen May 22 '14 at 00:14
  • I don't believe the two are mutually exclusive. I think there is an opportunity to teach here. Both PHP and how to be a good SO citizen. Especially since there is a coding effort. – John Conde May 22 '14 at 00:16
  • You are posting an answer while at the same time trying to avoid that other people can post an answer. I don't know if I would qualify that as `how to be a good SO citizen`. It is a bit long for a comment though :-) – jeroen May 22 '14 at 00:19
  • My voting to close is *not* an attempt to monopolize answering the question. – John Conde May 22 '14 at 00:21
0

You have a problem with your MySql syntax

In your query your field names should be written with back ticks not quotes. I would give an example but stack won't let me type back ticks.

MarshallOfSound
  • 2,629
  • 1
  • 20
  • 26
0

This part should have ticks:

    $imm=$_POST['im'];
    $doss=$_POST['nd'];
    $ass=$_POST['ns']; 
    $bn=$_POST['bn'];
    $trec=$_POST['T_rec'];
    $Erec=$_POST['e_rec'];
    $mt=$_POST['Mt'];
    $Drec=$_POST['Dt'];
    $INP=$_POST['inp'];
    $com=$_POST['comm'];

And this part should not have ticks(table fields):

$resultat=mysql_query("INSERT INTO rec_info (imma,INP,n_dossier,nom_benif,nom_ass,montant,type_rec,
date_rec,etat_rec,comm_rec,num_rec) Values
('$imm','$INP','$doss','$bn','$ass','$mt','$trec','$Drec','$Erec','$comm','')");

Remember that ticks in mysql is for variables only.

kimbarcelona
  • 1,136
  • 2
  • 8
  • 19