如何将include_path与insert查询一起使用

时间:2015-07-12 04:11:05

标签: php

该程序工作正常,运行甚至插入信息。但是,当您单击注册按钮时,它会显示goodReg.inc文件并在之后放入mysqli_query的die消息。所以基本上它表示用户注册成功,但无法连接到登录服务器。

网址= www.cameronwebsites.com/php/lesson5/register.php

我的代码:

<?php
 /* connection info */
ini_set("include_path","../../includes");
include("dbinfo.inc");
$cxn = mysqli_connect($host,$user,$password,$dbname) 
    or die("Couldn't connect to server.");
?>

foreach($good_data as $field => $value)
        {
            $good_data[$field] = mysqli_real_escape_string($cxn,$value);
        }

    $sql = "INSERT INTO UserInfo (user_id, password, first_name, last_name, city, country, email) VALUES ('$good_data[user_id]', '$good_data[password]', '$good_data[first_name]', '$good_data[last_name]', '$good_data[city]', '$good_data[country]', '$good_data[email]')";
include('goodReg.inc');
            $result = mysqli_query($cxn,$sql) or die("<p>**Couldn't connect to login server**</p>");     
            $row = mysqli_fetch($result);
             if ($row > 0)
            {
                $sql2 = "UPDATE TimeStamp SET time = CURRENT_TIMESTAMP where user_id='$good_data[user_id]'";  
                   $result2 = mysqli_query($cxn,$sql2) or die("<p>Couldn't Connect to Login</p>");

            }
            else
            {
                echo $message;
                extract($good_data);
                include('register.inc');
                exit();
            } 
        }   
    }
    else
    {
      include("register.inc");
    }



The $result = mysqli_query is where the connection dies, but not sure why

1 个答案:

答案 0 :(得分:0)

我需要摆脱mysqli_fetch函数,因为你不能在INSERT查询中使用该函数。

 $sql = "INSERT INTO UserInfo (user_id, password, first_name, last_name, city, country, email) VALUES ('$good_data[user_id]', '$good_data[password]', '$good_data[first_name]', '$good_data[last_name]', '$good_data[city]', '$good_data[country]', '$good_data[email]')";
    mysqli_query($cxn, $sql) or die ("Couldn't insert into UserInfo: " . mysqli_error($cxn));

            $sql2 = "UPDATE TimeStamp SET time = CURRENT_TIMESTAMP where user_id='$good_data[user_id]'";  
               $result2 = mysqli_query($cxn,$sql2) or die("Couldn't update TimeStamp: " . mysqli_error($cxn));
相关问题