doxp30826 2014-06-24 05:05 采纳率: 0%
浏览 8
已采纳

(更新)php在注册的同时创建两个东西?

I am going to create a register page to do the homework,and i can't found that simple answer of it.Here is the problem. i want to insert the new loginid and password in the a table call customerlist and create the new table named of the new loginid.

Here is the code:

$loginid = $_POST['loginid'];
$pw = $_POST['pw'];
$pw2 = $_POST['pw2'];

if($loginid != null && $pw != null && $pw2 != null && $pw == $pw2)
{ $sql = "insert into customerlist(LoginID,Password) values ('$loginid','$pw')";
  $sql="create table {$loginid} 
                (
  TradeID(50) VARCHAR(20),
  Trademode VARCHAR(10),
  Tradedate data,
  MTRdate   VARCHAR(50) ,
  Postaddress VARCHAR(255),
  Tel VARCHAR(15),
  Receivables int,
  Status VARCHAR(10)
                 );";



        if(mysql_query($sql))
        {
                echo 'success!';
                echo '<meta http-equiv=REFRESH CONTENT=2;url=index.php>';
        }
        else
        {
                echo 'fail!';
                echo '<meta http-equiv=REFRESH CONTENT=2;url=index.php>';
        }
}
else
{
        echo 'get out!';
        echo '<meta http-equiv=REFRESH CONTENT=2;url=index.php>';
}
?>

update

<?php

$con = mysql_connect("localhost","root","password");
mysql_select_db("babytradeapps");

$loginid = $_POST['loginid'];
$pw = $_POST['pw'];
$pw2 = $_POST['pw2'];
$name = $_POST['name'];
$telephone = $_POST['telephone'];
$idcard = $_POST['idcard'];
$email = $_POST['email'];
$bankac = $_POST['bankac'];
$plan = $_POST['plan'];
$date = $_POST['date'];

if($loginid != null && $pw != null && $pw2 != null && $pw == $pw2)
{ $sql = "insert into customerlist(LoginID,Password,Name,Phone,IDCARDNO,Email,BankACNO,Plan,Date) values ('$loginid','$pw','$name','$telephone','$idcard','$email','bankac','plan','date')";
  $sql2 = "insert into overall(LoginID,TradeID,Trademode,Tradedate,MTRdate,Postaddress,Tel,Receivables,Status) values ('$loginid','example','example','example','example','example','example','example','example')";
        if(mysql_query($sql)&& mysql_query($sql2))
        {
                echo 'success!';
                echo '<meta http-equiv=REFRESH CONTENT=2;url=index.php>';
        }
        else
        {
                echo 'fail!';
                echo '<meta http-equiv=REFRESH CONTENT=2;url=index.php>';
        }
}
else
{
        echo 'get out!';
        echo '<meta http-equiv=REFRESH CONTENT=2;url=index.php>';
}
?>

i have changed, but why the result is fail??? whats wrong of it?

  • 写回答

1条回答 默认 最新

  • doufu3718 2014-06-24 05:22
    关注

    You are overwriting your $sql variable with the insert statement right in the next line with the create table statement, so only the second command will be executed. Use a different variable for this and make two queries.

     $sql = "insert into customerlist(LoginID,Password) values ('$loginid','$pw')";
     $sql2="create table {$loginid} 
                     (
       TradeID(50) VARCHAR(20),
       Trademode VARCHAR(10),
       Tradedate data,
       MTRdate   VARCHAR(50) ,
       Postaddress VARCHAR(255),
       Tel VARCHAR(15),
       Receivables int,
       Status VARCHAR(10)
                      );";
     if(mysql_query($sql) && mysql_query($sql2))
    

    Also heed the warning of zerkms, creating so many tables is not a good database layout.

    Another note: You are using mysql_* functions that are becoming deprecated and will be removed from future versions of PHP. use mysqli_* or PDO instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧