保存检索到的数据

时间:2014-09-30 10:24:42

标签: php mysql oop pdo

在此页面上,我通过html组件显示数据。我会保存专栏" profil"从表格#34; favoris"

的列表中重新开始
<?php
require 'Connexion.php';
$c = new Connexion();
$c->query("select * from annonce where id_annonce=:id");
$c->bind(':id', $_GET['id']);
$r = $c->single();
?>
<!DOCTYPE html>
<html>
  <head>

    <title>Détails d'annonce</title>
</head>
  <body>
    <div id="Wraper">
  <div id="Middle">
    <div class="Left">

    <div class="Content FCKeditor">
          <h1><?php echo($r['profil']); ?></h1>
          <div class="Jobdetails">
              <form method="post" action="ajout_favoris.php?<?php echo($r['id_annonce']) ?>">
                  <p class="Date"><span></span> |
                      <span><a href="#"><?php echo($r['clt']); ?></a></span> |
                      <span><?php echo($r['contrat']); ?></span>
                      <span class="imageDroite">
                          <input type="submit" height="15" width="16" src="favoris-icon.png" value="ajouter aux favoris"/>
                      </span>
                  </p>
              </form>
              <?php echo text_format($r['d_annonce']); ?></br>
         </div>

           </div> </div>

    </div>
  </div>
  </body>
</html>

当我点击按钮时,数据库中没有保存任何内容。 ajout_favoris.php

<?php
require 'Connexion.php';
$c = new Connexion();
$c->query("insert into favoris (titre_fav) select profil from annonce where id_annonce =:id");
$c->bind(':id', $_GET['id_annonce']);
$c->execute();
header("location: javascript:history.go(-1);");
?>

1 个答案:

答案 0 :(得分:0)

你必须使用get并且必须指定一个字符串来传递查询字符串 action =“ajout_favoris.php?id_annonce =”

    <div class="Content FCKeditor">
      <h1><?php echo($r['profil']); ?></h1>
      <div class="Jobdetails">

              <p class="Date"><span></span> |
                  <span><a href="#"><?php echo($r['clt']); ?></a></span> |
                  <span><?php echo($r['contrat']); ?></span>
                  <span class="imageDroite">
                     <a href="ajout_favoris.php?id_annonce = <?php echo($r['id_annonce']) ?>"> 
              ajouter aux favoris</a>//changed line
                  </span>
              </p>
          <?php echo text_format($r['d_annonce']); ?></br>
     </div>

       </div> </div>

</div>