Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何为特定成员插入唯一数据_Php_Mysql - Fatal编程技术网

Php 如何为特定成员插入唯一数据

Php 如何为特定成员插入唯一数据,php,mysql,Php,Mysql,这是我在MYSQL中的表,我想为成员id插入唯一的记录,这意味着成员id=1可以有多个记录,但它应该是唯一的,我是通过PHP页面插入的,但编码工作不正常 create table contact_viewed( contact_viewed_id int(11) not null auto_increment, contacted_member_id int (11) not null, member_id int(11) not null, primar

这是我在MYSQL中的表,我想为成员id插入唯一的记录,这意味着成员id=1可以有多个记录,但它应该是唯一的,我是通过PHP页面插入的,但编码工作不正常

    create table contact_viewed(
    contact_viewed_id int(11) not null auto_increment,
    contacted_member_id int (11) not null,
    member_id int(11) not null,
    primary key(contact_viewed_id)
    );
我的php文件如下所示

 <?php
    include_once 'dbconfig.php';
    if (! $user->is_loggedin ()) {
    $user->redirect ( 'login.php' );
    }
    $m_id = $_SESSION ['user_session'];
    $stmt = $DB_con->prepare ( "SELECT * FROM member WHERE member_id=:member_id" );
    $stmt->execute ( array (
    ":member_id" => $m_id 
    ) );
    $userRow = $stmt->fetch ( PDO::FETCH_ASSOC );
    ?>


    <?php
    $stmt7 = $DB_con->prepare ( "SELECT * FROM contact_viewed WHERE member_id=:member_id" );
    $stmt7->bindParam ( ":member_id", $m_id );
    $stmt7->execute ();
    $row2 = $stmt7->fetchAll ();
    if ($stmt7->rowCount () > 0) {
    foreach ( $row2 as $data ) {
     if ($data ['member_id'] == $m_id) {enter code here
     if($data ['contacted_member_id'] == $_GET['id']){
         echo "do nothing1";
     }
     else{
         $stmt6 = $DB_con->prepare ( "INSERT INTO contact_viewed(contacted_member_id,member_id) VALUES(:contacted_member_id,:member_id)" );
         $stmt6->bindParam ( ":contacted_member_id", $_GET ['id'] );
         $stmt6->bindParam ( ":member_id", $m_id );
         $stmt6->execute ();
         echo "hello";
     }
     } 
    } 
    }
    else{
    $stmt6 = $DB_con->prepare ( "INSERT INTO contact_viewed(contacted_member_id,member_id) VALUES(:contacted_member_id,:member_id)" );
    $stmt6->bindParam ( ":contacted_member_id", $_GET ['id'] );
    $stmt6->bindParam ( ":member_id", $m_id );
    $stmt6->execute ();
    $available_contact = $userRow ['available_contact'];
    $available_contact = $available_contact - 1;
    $stmt5 = $DB_con->prepare ( "UPDATE member SET available_contact=:available_contact WHERE member_id=:member_id" );
    $stmt5->bindParam ( ":available_contact", $available_contact );
    $stmt5->bindParam ( ":member_id", $m_id );
    $stmt5->execute ();
    echo "ok ok";
    }
    ?>
    <?php
    require 'script.php';
    ?>

    <!-- close all connection at the end of the page -->

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>

    <?php
    require 'css.php';
    ?>

    <?php
    require 'config.php';
    ?>

   <link rel="stylesheet" href="style.css" />
   <link rel="stylesheet" href="css/theme-inner.css" />
   </head>
   <body>
    <?php
    require 'nav.php';
    ?>

    <div align="center">
    <h1>Contact Detail</h1>
    </div>

    <section class="full-width-inner">
    <div class="container">
    <div class="row" style="margin: 0 auto;">
     <div class="col-lg-12 col-md-12" style="margin: 0 auto;">
     <h2 class="article-title">Profile</h2>
     <div class="row">
         <?php require 'leftNav.php';?>

    <?php

    if (isset ( $_GET ['id'] )) {
    $search = trim ( $_GET ['id'] );
    $result = mysqli_query ( $conn, "select * from member where member_id like '%" . $search . "%' Limit 1" );
    $rows = mysqli_num_rows ( $result );
    if ($rows) {
    while ( $post = mysqli_fetch_assoc ( $result ) ) {
     ?>




     <div class="col-sm-8 col-md-9 col-lg-9">
         <div class="panel panel-info light-pink">
          <div class="panel-heading action-box">
          <div class="panel-caption">
              <h3 class="panel-title"><?php print($post['member_name']); ?></h3>
          </div>
          <!-- panel-caption -->
          <div class="panel-tools">
              <a href="view_profiles_others.php?id=<?php echo $search ?>"
              class="btn btn-white-outline btn-xsmall">View Member Profile</a>
          </div>
          <!-- panel-tools -->

          <div class="panel-tools">
              <a href="view_contact.php?id=<?php echo $search ?>"
              class="btn btn-white-outline btn-xsmall">View Contact Deatil</a>
          </div>
          <!-- panel-tools -->
          </div>
          <!-- panel panel-info light-pink -->
          <div class="panel-body">

          <div class="row">
              <div class="col-md-4 col-lg-3">
              <a href="view_contact.php?id=<?php echo $search;?>"><img
               alt="Image Not Available"
               src="<?php echo $post['upload_image_path'];?>"
               class="thumbnail" /></a>
              </div>
              <!-- col-md-4 col-lg-3 -->
              <div class="col-md-8 ">
              <div class="profile-sumup">

               <div class="row">
               <table class="table table-condensed table-user-information">
                <tbody>
                <tr>
                    <td class="col-xs-4 col-sm-4">Name</td>
                    <td><span>:</span> <?php echo $post['member_name'];?></td>
                </tr>
                <tr>
                    <td class="col-xs-4 col-sm-4">Date Of Birth</td>
                    <td><span>:</span> <?php echo $post['day'];?>/<?php echo $post['month'];?>/<?php echo $post['year'];?></td>
                </tr>
                    <?php
     $year = $userRow ['year'];
     $y = date ( "Y" );
     $age = $y - $year;
     ?>
                    <tr>
                    <td class="col-xs-4 col-sm-4">Age</td>
                    <td><span>:</span> <?php echo $age;?></td>
                </tr>
                <tr>
                    <td class="col-xs-4 col-sm-4">Email</td>
                    <td><span>:</span> <?php echo $post['email'];?></td>
                </tr>
                <tr>
                    <td class="col-xs-4 col-sm-4">Country</td>
                    <td><span>:</span> <?php echo $post['country'];?></td>
                </tr>

                <tr>
                    <td class="col-xs-4 col-sm-4">Residing State</td>
                    <td><span>:</span> <?php echo $post['residing_state'];?></td>
                </tr>
                <tr>
                    <td class="col-xs-4 col-sm-4">City</td>
                    <td><span>:</span> <?php echo $post['city'];?></td>
                </tr>
                <tr>
                    <td class="col-xs-4 col-sm-4">Contact Address</td>
                    <td><span>:</span> <?php echo $post['contact_address'];?></td>
                </tr>

         <tr>
          <td class="col-xs-4 col-sm-4">Primary Mobile Number</td>
           <td><span>:</span> <?php echo $post['primary_mobile_number'];?></td>
                </tr>
                <tr>
                    <td class="col-xs-4 col-sm-4">Alternate Mobile Number</td>
                    <td><span>:</span> <?php echo $post['alternate_mobile_number'];?></td>
                </tr>
                <tr>
                    <td class="col-xs-4 col-sm-4">Citizenship</td>
                    <td><span>:</span> <?php echo $post['citizenship'];?></td>
                </tr>
                <tr>
                    <td class="col-xs-4 col-sm-4">Residing Status</td>
                    <td><span>:</span> <?php echo $post['residing_status'];?>  </td>
                </tr>
                </tbody>
               </table>
               <!-- table -->
               </div>
               <!-- /row -->
              </div>
              <!-- profile-sumup -->



              </div>
              <!-- col-md-8 -->

          </div>
          <!-- row -->

          </div>
          <!-- panel-body -->
         </div>
         <!-- col-sm-8 col-md-9 col-lg-9 -->

     <?php
    }
    } else {

    ?>
     <div class="col-sm-8 col-md-9 col-lg-9">
          <div class="panel panel-info light-pink">
          <div class="panel-heading action-box">
              <div class="panel-caption">
     <h3 class="panel-title"><?php echo "No Record Found In The  Database!"?></h3>
              </div>
              <!-- panel-caption -->
          </div>
          <!-- panel-heading action-box -->
          </div>
          <!-- panel panel-info light-pink -->



         </div>
         <!-- col-sm-8 col-md-9 col-lg-9 -->
              <?php
     }
     }

     ?>

         </div>
         <!-- row -->
     </div>
     <!-- col-lg-12 col-md-12 -->
     </div>
     <!-- row -->
     </div>
      <!-- container -->

     </section>
     <!-- full-width-inner -->

     </body>
     </html>

联系方式
轮廓
名称
: 
出生日期
: //
年龄
: 
电子邮件
: 
国家
: 
居住国
: 
城市
: 
联系地址
: 
主要手机号码
: 
备用移动电话号码
: 
公民身份
: 
居住状态
:   

这是一大堆“工作不正常”的代码。这意味着什么?是否允许同一个联系的成员id与多个不同的成员id关联?如果是,则您的主键必须包含这两列(或使用自动递增主键并将唯一键添加到这两列中)-每对都是唯一的,但每列每次都可以包含与不同值成对的重复值。如果是这样的话,那么就根本不需要自动递增列了。@AndySavage谢谢您的回复,它正在工作,但不是我想要的插入…@ArifKhan这几乎是一样有用的。。我们没有水晶球来看看你想要什么。您需要指定您希望它做什么以及它正在做什么,显示一些示例等。帮助我们帮助您。