0

以下代码由教程编写。数据库结构在这里:http ://www.shareimages.com/image.php?62275-pJqgl5ejk6Col5yVnaY-local_mysql_screen.gif

如果我尝试将数据插入更简单的“成员”表,代码运行良好,但不适用于“用户”表。在这种情况下,我无法弄清楚障碍。请推荐一些解决方案。

<?php
function PrepSQL($value)
{
    // Stripslashes
    if(get_magic_quotes_gpc())
    {
        $value = stripslashes($value);
    }
    // Quote
    $value = "'" . mysql_real_escape_string($value) . "'";
    return($value);
}

    if(!empty($_POST['submit'])) {

        $company=$_POST['company'];
        $vat=$_POST['vat'];
        $city=$_POST['city'];
        $zip=$_POST['zip'];
        $str=$_POST['str'];
        $nr=$_POST['nr'];
        $other=$_POST['other'];
        $email=$_POST['email'];
        $tel=$_POST['tel'];
        $url=$_POST['url'];

        $db = mysql_connect('localhost', 'asd', 'asdpass');
        if(!$db) die("Error connecting to MySQL database.");
        mysql_select_db("fc" ,$db);

        $sql = "INSERT INTO member (company,vat,city,zip,str,nr,other,email,tel,url) VALUES (".
                 PrepSQL($company) . ", " .
                 PrepSQL($vat) . ", " .
                 PrepSQL($city) . ", " .
                 PrepSQL($zip) . ", " .
                 PrepSQL($str) . ", " .
                 PrepSQL($nr) . ", " .
                 PrepSQL($other) . ", " .
                 PrepSQL($email) . ", " .
                 PrepSQL($tel) . ", " .
                 PrepSQL($url) . ")";

        mysql_query($sql);
        echo "data saved";
    }
?>
<form action="#" method="POST" >
    <input name="company" type="text" id="company" class="text required" placeholder="Cégnév" />
    <input name="vat" type="text" id="vat" class="text " placeholder="Adószám" />
    <fieldset>
    <select name="city" id="city" class="item select city r4 required " title="Település kiválasztása" placeholder="Település"  />
        <option value="31353">Aba</option><option value="16547">Abádszalók</option>
    </select>
    <input name="zip" type="text" id="zip" class="text required" placeholder="isz." />
    <input name="str" type="text" id="str" class="text required" placeholder="közterület neve" />
    <input name="nr" type="text" id="nr" class="text required" placeholder="szám" />
    <input name="other" type="text" id="other" class="text " placeholder="egyéb" />
    <input name="email" type="email" pattern="[^ @]*@[^ @]*" id="email" class="text required" placeholder="email" value="@" />
    <input name="tel" type="tel" pattern="[\+]\d{2}[\ ]\d{2}[\ ]\d{4}\d{3}" id="tel" class="text required" value="+36 " title="Telefonszám: +36 00 1234567"  placeholder="+36 00 1234567" />
    <input name="url" type="url" id="url" class="text " value="http://" />
    <input name="submit" type="submit" value="Adatok elküldése" class="submit" />
</form>
4

2 回答 2

1

在您的 SQL 查询中,它不是表“用户”而不是“成员”吗?

 $sql = "INSERT INTO user (company,vat,city,zip,str,nr,other,email,tel,url) VALUES (".
                 PrepSQL($company) . ", " .
                 PrepSQL($vat) . ", " .
                 PrepSQL($city) . ", " .
                 PrepSQL($zip) . ", " .
                 PrepSQL($str) . ", " .
                 PrepSQL($nr) . ", " .
                 PrepSQL($other) . ", " .
                 PrepSQL($email) . ", " .
                 PrepSQL($tel) . ", " .
                 PrepSQL($url) . ")";
于 2012-10-31T08:31:13.190 回答
0

您的插入语句有缺陷。给定的列与您的 db 列不匹配。

$sql = "INSERT INTO member (company,vat,city,zip,str,nr,other,email,tel,url)

将“电话”更改为“电话”,它应该可以工作。

于 2013-06-08T12:35:58.470 回答