dongpan9760 2017-02-01 10:40
浏览 14
已采纳

计数点击弹出注册在phpmyadmin [关闭]

I have a problem. The IP doesn't appears in the other table (in the same db).

In the page "recette1.php?id=1"

<?php
$bdd = new PDO('mysql:host=localhost;dbname=recettes', 'root', 'root');

include("C:/wamp64/www/doc/ip_visiteurs.php");


$req = $bdd->prepare('UPDATE cuisine SET visiteurs = visiteurs + 1');
$req->execute();
$req->closeCursor();

$req = $bdd->prepare('SELECT id_recette, visiteurs FROM cuisine');
$req->execute();
$data = $req->fetch(PDO::FETCH_OBJ);
$req->closeCursor();
?>
<?php echo $data->visiteurs;?> personnes ont vu cette recette.

ip_visiteurs.php

<?php

$bdd = new PDO('mysql:host=localhost;dbname=recettes', 'root', 'root');


$ip_user = $_SERVER['REMOTE_ADDR'];

$ins = $bdd->query('INSERT INTO info_visiteurs(ip) VALUES(\'' . $ip_user .'\') WHERE id_recette="1"');




?>
  • 写回答

1条回答 默认 最新

  • dpn68721 2017-02-01 10:48
    关注

    You need a database connection to do it the way you are wanting to. I assume you have set up a database in phpmyadmin to write the data to.

    In the (new?) PHP file which will record the data onclick you should include the following:

    <?php
            $bdd = new PDO('mysql:host=localhost;dbname=recettes', 'root', 'root');
            $req = $bdd->prepare('SELECT id_recette, visiteurs FROM cuisine');
            $req->execute();
            $data = $req->fetch(PDO::FETCH_OBJ);
            $req->closeCursor();    
    ?>
    
        <a href="javascript:void();" onclick="javascript:open_infos_1()"><div class="item">
            <div id="chateauchoco2" class="opac">
    
            <img src="../Dalila/chateauchoco2.png" onclick="document.getElementById('overlay3').style.display='block'" width="280" height="321"/>
    
            </div>
            </div>
            </a>
    
            <?php echo ($visiteurs);?> personnes ont vu cette recette.
            <script type="text/javascript">
    
            function open_infos_1()
            {
            window.open('recette1.php?id=1','recette1','menubar=no, scrollbars=no, top=50, left=100, width=800, height=600');
            }
            </script>
    

    PHP

    <?php
    $bdd = new PDO('mysql:host=localhost;dbname=recettes', 'root', 'root');
    
    $req = $bdd->prepare('UPDATE cuisine SET visiteurs = visiteurs + 1');
    $req->execute();
    $req->closeCursor();
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?