0
<?php
    if(isset($_POST['btnSubmit1'])){
$fullName=htmlentities(mysql_real_escape_string($_POST['name']));
    $emailID=htmlentities(mysql_real_escape_string($_POST['email']));

    $mobNo=htmlentities(mysql_real_escape_string($_POST['mobile']));
    $c=htmlentities(mysql_real_escape_string($_POST['city']));
    $p=htmlentities(mysql_real_escape_string($_POST['pincode']));
    $t=$_POST['type'];
    $tm=time();



    $query = 'PREPARE statement FROM "INSERT INTO agrl
VALUES(?,?,?,?,?,?,?)"';
mysql_query($query);
$query = 'SET @name = "$fullName",' .
'@email = "$emailID",' .
'@mobo = "$mobNo",' .
'@city = "$c",' .
'@pincode = "$p",'.
'@country = "$t",'.
'@time = "$tm"';

$query = 'EXECUTE statement USING 
@name,@email,@mobo,@city,@pincode,@country,@time';

    if(!(mysql_query($query))){
        echo "Sorry!!! please try again";
    }
    else{
        $query = 'DEALLOCATE PREPARE statement';
mysql_query($query);
        echo "<script     
type='text/javascript'>alert('success')</script>";



}
}

?>

这段代码完全可以工作 f9 但不是从表单字段插入数据而是插入变量名例如:如果我在表单的名称字段中键入 robert 并点击提交按钮然后而不是在我的数据库中保存 robert 它保存 $fullName.. 请帮助.. 提前致谢

4

2 回答 2

-1

PHP 仅在双引号字符串中用字符串中的 teirs 值替换变量。只需更改查询中的引号

$query = "SET @name = \"$fullName\"," .
"@email = \"$emailID\"," .
"@mobo = \"$mobNo\"," .
"@city = \"$c\"," .
"@pincode = \"$p\",".
"@country = \"$t\",".
"@time = \"$tm\"";
于 2013-10-01T13:31:48.803 回答
-2

问题在这里:

$query = 'SET @name = "$fullName",' .
'@email = "$emailID",' .
'@mobo = "$mobNo",' .
'@city = "$c",' .
'@pincode = "$p",'.
'@country = "$t",'.
'@time = "$tm"';

PHP 单引号不允许你在里面添加变量。改用双引号,或连接字符串,如'SET @email = "'.$emailID.'",'

于 2013-10-01T13:30:45.307 回答