0
<?php
    $m        = "arushi";
    $em       = "SELECT emailid FROM tblregister WHERE name='$m'";
    $q        = mysql_query($em);
    $n        = mysql_fetch_assoc($q);
    $fullName = mysql_real_escape_string($_POST['name']);
    $address  = mysql_real_escape_string($_POST['address']);
    $mobNo    = mysql_real_escape_string($_POST['dinner']);
    $summary  = "jsf";
    $sql      = "INSERT INTO tbljcustomer VALUES('$m', '$n', '$fullName',     
    '$address','$mobNo', '$summary')";

    if(!(mysql_query($sql)))
    {
        echo "Sorry!!! we were unable to process please try again";
    }
    else
    {
        echo "customized";
    }
?>

执行此操作时一切正常,只是它不从 tblregister 获取 emailid,而是仅显示 Array 或有时显示资源 id#10。提前致谢

4

7 回答 7

3

用这个:

$n=mysql_fetch_assoc($q);
$emailid = $n['emailid'];

您的查询将更改为

$sql="insert into tbljcustomer values('$m', '$emailid', '$fullName','$address','$mobNo', '$summary')";
于 2013-09-12T10:01:29.587 回答
0

你必须使用:$n['emailid']

于 2013-09-12T09:58:01.233 回答
0

$n 是一个关联数组。查看mysql_fetch_assoc的文档。var_dump($n);如果您想查看数组的结构,请使用。从文档中:

mysql_fetch_assoc 返回与获取的行相对应的字符串关联数组,如果没有更多行,则返回 FALSE。

于 2013-09-12T09:58:14.557 回答
0

mysql_fetch_assoc返回一个数组尝试:

insert into tbljcustomer values('$m', '".$n['emailid']."', '$fullName',...
于 2013-09-12T09:59:21.037 回答
0

代替

$n

$n['emailid']

在您的插入查询中

于 2013-09-12T10:00:09.477 回答
0

这将是

$email = $n['emailid'];

$sql="insert into tbljcustomer values('$m', '$email', '$fullName',     
'$address','$mobNo', '$summary')";
于 2013-09-12T10:01:16.840 回答
0

代替

$sql      = "INSERT INTO tbljcustomer VALUES('$m', '$n', '$fullName',     
'$address','$mobNo', '$summary')";

$sql      = "INSERT INTO tbljcustomer VALUES('$m', '".$n['emailid']."', '$fullName',     
'$address','$mobNo', '$summary')";
于 2013-09-12T10:01:24.313 回答