简体   繁体   English

奇怪的MySQL问题

[英]Strange MySQL Issues

So I setup a table using mysql query browser, and now i'm trying to fill it up. 因此,我使用mysql查询浏览器设置了一个表,现在我试图填充它。 But no matter what I do, it says "created account succesfully", but nothing ever gets added to the database! 但是无论我做什么,它都说“成功创建了帐户”,但是没有任何东西被添加到数据库中!

The code I have is below: 我的代码如下:

` `

            if($connection)
            {
                $out =
                    "<p>Please wait while we process your request.</p>";

                mysql_select_db(
                    "accounts",
                    $connection
                );

                    // Generate Account Number.
                    $AccountNumber = rand(17000, 904870);

                    // Set Account Values.
                    $GenuineUser = 0;
                    $VerifiedAdvertiser = 0;
                    $DateOfBirth =
                        $_POST["bmoth"] . "/" . $_POST["bday"] . "/" . $_POST["byear"];

                    // MD5 the Account ID.
                    $AccountID = md5($_POST["AccountID"]);
                // Create Advertiser Account.
                mysql_query(
                    "INSERT INTO accounts.advertisers (
                        'Account Number',
                        'Account ID',
                        'First Name',
                        'Last Name',
                        'Date Of Birth',
                        'Email Address',
                        'Phone Number',
                        'Street Address',
                        'City',
                        'Zip Code',
                        'State',
                        'Country',
                        'Genuine User',
                        'Verified Advertiser') VALUES (
                            '".$AccountNumber."',
                            '".$_POST["AccountID"]."',
                            '".$_POST["FirstName"]."',
                            '".$_POST["LastName"]."',
                            '".$DateOfBirth."',
                            '".$_POST["EmailAddress"]."',
                            '".$_POST["PhoneNumber"]."',
                            '".$_POST["StreetAddress"]."',
                            '".$_POST["City"]."',
                            '".$_POST["ZipCode"]."',
                            '".$_POST["State"]."',
                            '".$_POST["Country"]."',
                            '".$GenuineUser."',
                            '".$VerifiedAdvertiser."')
                ");

                // Setup Advertisement Table.


                // Assume account created successfully.
                $out =
                    "<p>Advertiser Account created.</p>";
            }
            else
            {
                die('Oh, @#%#!: ' . mysql_error());
            }
            mysql_close($connection);
        }
        else
        { 
                                    // else, display form. 
                           } ?>

` `

Could somebody kindly help me sort this out, please? 有人可以帮我解决这个问题吗? I'd appreciate any help at all. 我会感激任何帮助。

Thank you 谢谢

update So, I've managed to figure out what was going to, thanks to all your advice :) As it turns out, it wasn't working because I was using spaces inbetween the Column Names (ie Account ID should be AccountID). 更新因此,由于您的所有建议,我设法弄清楚了要做什么:)事实证明,该行不通是因为我在列名之间使用空格(即,帐户ID应该是AccountID)。 So I just removed spaces from the table columns, and also from the php code. 因此,我只是从表列以及php代码中删除了空格。

Thanks all for your help! 感谢你的帮助!

You really should be checking for errors in your query. 您确实应该检查查询中的错误。 Even something as basic as: 甚至是一些基本的东西:

mysql_query($query) or die(mysql_error());

Any time you do a mysql function you should check for errors, or have a method of catching exceptions (if using an applicable interface, since the default mysql functions don't throw exceptions). 每当您执行mysql函数时,都应该检查错误或具有捕获异常的方法(如果使用适用的接口,因为默认的mysql函数不会引发异常)。

It could be messing up on a few points. 它可能在几点上搞砸了。

Also, as a hint, sprintf works wonderfully if you're writing queries out. 另外,作为提示,如果您要写出查询,则sprintf可以很好地工作。

You have an error in your SQL query. 您的SQL查询中有一个错误。 You're getting "Account created" because you're not testing for it. 您正在获取“已创建帐户”,因为您没有对此进行测试。

So, I've managed to figure out what was going to, thanks to all your advice :) As it turns out, it wasn't working because I was using spaces inbetween the Column Names (ie Account ID should be AccountID). 因此,由于您的所有建议,我设法弄清楚了要做什么:)事实证明,它没有用,因为我在列名之间使用空格(即,帐户ID应该是AccountID)。 So I just removed spaces from the table columns, and also from the php code. 因此,我只是从表列以及php代码中删除了空格。

Thanks all for your help! 感谢你的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM