如何使用PHP和mysql将数据插入2个表? [英] How do I insert data into 2 tables using PHP and mysql ?

查看:65
本文介绍了如何使用PHP和mysql将数据插入2个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个公交预订系统,其中管理员是唯一允许创建公交运营商的人,然后运营商可以创建公交车,路线和车票。用户可以在线购买机票或使用移动应用程序。我试图将所有用户登录详细信息保存在一个表中,并将配置文件信息保存在与用户匹配的表中,例如运算符表中的总线运算符,客户表中的客户和管理员表中的管理员。现在我有一个用于添加运算符的表单,该表单应该保存在登录表和运算符表中。



我尝试了什么: < br $> b $ b

I am working on a bus reservation system where the admin is the only one allowed to creator bus operators and then the operators can create Buses, routes and tickets. The user can buy a ticket online or using a mobile app. I am trying to save all my user login details in one table and the profile information in a table that matches the user for example The bus operators in the operator table, The Customers in the Customer Table and the Admin in the Admin table. Now i have a form for adding operators which is supposed to save in the login table and operators table.

What I have tried:

<?php
    $uname=(isset($_POST['uname']))?$mk->real_escape_string(trim($_POST['uname'])):'';
    $name=(isset($_POST['name']))?$mk->real_escape_string(trim($_POST['name'])):'';
    $person=(isset($_POST['person']))?$mk->real_escape_string(trim($_POST['person'])):'';
    $mobile=(isset($_POST['mobile']))?$mk->real_escape_string(trim($_POST['mobile'])):'';
    $email=(isset($_POST['email']))?$mk->real_escape_string(trim($_POST['email'])):'';
    $site=(isset($_POST['site']))?$mk->real_escape_string(trim($_POST['site'])):'';
   
   $ocreate = "INSERT INTO tbloperator
   (op_id,op_name,op_contact,op_mobile,op_email,op_website,op_logo) 
               values('{$name}','{$person}','{$mobile}','{$email}','{$site}','')";

   //$insert="update tbladmins set a_name='$name',a_city='$city',a_mobile='$mobile',a_mail='$email'
     //       where l_user='$user'" ;

    $pwd = "MyKiti12034";
    $pass = $msec -> hashpass ($pwd);

  $trial = "INSERT INTO tbllogin(l_user,l_pass,l_access) VALUES ({$uname},{$pass},2)";
  

            
    if(isset($_POST['oadd'])){

      $mk->query($trial);
      $last_insert = mysqli_insert_id();

      if(!empty($op_id))
      {
    
            if($mk->query($ocreate)){
              echo '<div data-alert class="alert-box success radius">';
                echo  'Success ! Operator Profile created successfully';
                echo  '<a href="#" class="close">×</a>';
              echo '</div>';
              header('refresh:2;url=dashboard.php');
              
              }else{
              echo '<div data-alert class="alert-box warning radius">';
                echo  'Error ! '.$mk->error;
                echo  '<a href="#" class="close">×</a>';
              echo '</div>';
              }
            
            
          }         
     }
  ?>

推荐答案

uname =(isset(
uname=(isset(


_POST ['' uname']))?
_POST['uname']))?


mk-> real_escape_string(trim(
mk->real_escape_string(trim(


这篇关于如何使用PHP和mysql将数据插入2个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆