anon271334
anon271334

Reputation:

Strange MySQL Issues

So I setup a table using mysql query browser, and now i'm trying to fill it up. 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 (i.e. Account ID should be AccountID). So I just removed spaces from the table columns, and also from the php code.

Thanks all for your help!

Upvotes: 0

Views: 130

Answers (3)

anon271334
anon271334

Reputation:

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 (i.e. Account ID should be AccountID). So I just removed spaces from the table columns, and also from the php code.

Thanks all for your help!

Upvotes: 0

eusto
eusto

Reputation: 5

You have an error in your SQL query. You're getting "Account created" because you're not testing for it.

Upvotes: 1

Codeacula
Codeacula

Reputation: 2368

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).

It could be messing up on a few points.

Also, as a hint, sprintf works wonderfully if you're writing queries out.

Upvotes: 1

Related Questions