PHP插入$ DB不适用于Windows Server :(

时间:2011-03-15 15:58:50

标签: php mysql insert windows-server

我最近购买了一家公司,其网站包含不同客户的数据库。它是使用PHP构建的。

我将网站从其现有服务器(Linux)移至我的公司服务器(Windows Server 2008)。

我创建并导入了数据库并将所有内容连接起来。

我仍然可以编辑现有客户端的信息但是当我尝试这样时,在数据库中创建新条目的功能停止工作。

我很肯定没有文件被更改,而且这是一个在其他服务器上运行的功能。

以下是输入信息的代码

$sql = "insert into $DB.cleints (client_id, client_phone) values ($client_id, $client_phone) on duplicate key update client_id='$client_id', client_phone='$client_phone'";

mysql_query($sql);

if (mysql_errno() != 0) {
    echo "Sorry, there was an error adding this client";
    echo "\nsql=$sql\n";
    echo mysql_error();
}

2 个答案:

答案 0 :(得分:0)

  

错误很抱歉,有一个   添加此客户端时出错sql = insert   到databasename.clients(client_id,   client_phone)值(1,   '18005555555')重复密钥更新   CLIENT_ID = 1,   第1行的client_phone ='18005555555'

阅读您发布的错误消息。

  

“重复密钥更新client_id = 1,client_phone ='18005555555'”

表中是否已记录了这两个值? client_id&是否有唯一索引? client_phone?

答案 1 :(得分:0)

我是mysql和php编码的新手。我遇到了同样的问题,访问mysql的基本方法完美无缺。这是我的代码

<?php
$server = "localhost";
$user = "cscs";
$password = "C0va!CaRe";
$database = "cscs";

$link = mysqli_connect($server, $user, $password, $database);

if(!$link){
    echo "Error connecting database, ".mysql_error();
}

?>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP MySQL Test 1</title>
</head>

<body>

<h2 style="text-align: center;">Database Test 1 - Creating a table manually and updating through form</h2>

<form name="register" id="register" action="" method="post">

    <table width="60%" cellspacing='1' cellpadding="10" border="1">
        <tr>
            <td width="45%" valign="middle" align="left">Full Name</td>
            <td width="55%" valign="middle" align="left"><input type="text" name="full-name" id="full-name"></td>
        </tr>

        <tr>
            <td width="45%" valign="middle" align="left">Email</td>
            <td width="55%" valign="middle" align="left"><input type="text" name="email" id="email"></td>
        </tr>

        <tr>
            <td width="45%" valign="middle" align="left">Phone</td>
            <td width="55%" valign="middle" align="left"><input type="text" name="phone" id="phone"></td>
        </tr>

        <tr>
            <td width="45%" valign="middle" align="left">City</td>
            <td width="55%" valign="middle" align="left"><input type="text" name="city" id="city"></td>
        </tr>

        <tr>
            <td width="45%" valign="middle" align="left">Country</td>
            <td width="55%" valign="middle" align="left"><input type="text" name="country" id="country"></td>
        </tr>

        <tr>
            <td width="45%" valign="middle" align="left">User Name</td>
            <td width="55%" valign="middle" align="left"><input type="text" name="username" id="username"></td>
        </tr>

        <tr>
            <td width="45%" valign="middle" align="left">Password</td>
            <td width="55%" valign="middle" align="left"><input type="text" name="pass" id="pass"></td>
        </tr>

        <tr>
            <td width="45%" valign="middle" align="left">Confirm Password</td>
            <td width="55%" valign="middle" align="left"><input type="text" name="cpass" id="cpass"></td>
        </tr>

        <tr>
            <td valign="middle" align="left" colspan="2"><input type="submit" name="submit" value="Register"></td>

        </tr>

    </table> 

</form>

<?php

if(isset($_POST['submit'])){

    $fullname = $_POST['full-name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $city = $_POST['city'];
    $country = $_POST['country'];
    $username = $_POST['username'];
    $pass = $_POST['pass'];

    mysqli_select_db($link,'cscs');

    $sql1 = "INSERT INTO userinfo (fullname, email, phone, city, country, username, password) VALUES ('{$fullname}', '{$email}', '{$phone}', '{$city}', '{$country}', '{$username}', '{$pass}')";

    if(mysqli_query($link, $sql1)) {

        echo "Data inserted to database";   

    }

    else {
        echo "Error updating database, ".mysql_error();
    }


}

?>

</body>
</html>