当我从表中检索值到另一个时,它插入了空白

时间:2010-09-24 13:28:34

标签: php database

我有两张桌子

  1. 用户
  2. registered_members
  3. 我想确认用户表中的值,然后将其插入registered_members表中   但问题是..从用户表中选择的值很好,但是在带有空值的registered_members中插入 为什么?

    <?
    include('conf.php');
    
    // Passkey that got from link
    $passkey=$_GET['passkey'];
    
    $tbl_name1="users";
    
    // Retrieve data from table where row that match this passkey
    $sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
    $result1=mysql_query($sql1) or die ("error1") ;
    
    // If successfully queried
    if($result1){
    
    // Count how many row has this passkey
    $count=mysql_num_rows($result1);
    
    // if found this passkey in our database, retrieve data from table "users"
    if($count==1){
    
    $rows=mysql_fetch_array($result1);
    $username=$_POST['uname'];
    $fname=$_POST['fname'];
    $password=$_POST['password'];
    $email=$_POST['email'];
    $age=$_POST['age'];
    $gender=$_POST['gender'];
    
    $tbl_name2="registered_members";
    
    // Insert data that retrieves from "users" into table "registered_members"
    $sql2=("INSERT INTO $tbl_name2 (uname,fname,password,email,age,gender)VALUES('$username','$fname','$password','$email','$age','$gender')");
    $result2=mysql_query($sql2) or die ("error insert");
    }
    
    // if not found passkey, display message "Wrong Confirmation code"
    else {
    echo "Wrong Confirmation code";
    }
    
    // if successfully moved data from table"users" to table "registered_members" displays message "Your account has been activated" and don't forget to delete confirmation code from table "users"
    if($result2){
    
    echo "Your account has been activated";
    
    // Delete information of this user from table "temp_members_db" that has this passkey
    $sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";
    $result3=mysql_query($sql3);
    
    }
    
    }
    ?>
    

2 个答案:

答案 0 :(得分:1)

因为你使用的是$ _POST而不是#rows

更改

$rows=mysql_fetch_array($result1); 
$username=$_POST['uname']; 
$fname=$_POST['fname']; 
$password=$_POST['password']; 
$email=$_POST['email']; 
$age=$_POST['age']; 
$gender=$_POST['gender'];  

$rows=mysql_fetch_array($result1); 
$username=$rows['uname']; 
$fname=$rows['fname']; 
$password=$rows['password']; 
$email=$rows['email']; 
$age=$rows['age']; 
$gender=$rows['gender'];

答案 1 :(得分:0)

在所有这些行中将$_POST更改为$row

$username=$_POST['uname'];
$fname=$_POST['fname'];
$password=$_POST['password'];
$email=$_POST['email'];
$age=$_POST['age'];
$gender=$_POST['gender'];

因为您要将$row中的结果作为$rows=mysql_fetch_array($result1);

提取