[MySQL] Why is MySQL being a bitch?

Status
Not open for further replies.

brsy

nah mang
May 12, 2011
1,530
272
I know this is right, but why isn't it working?!
PHP:
if(!isset($error)) {
    $ip = $_SERVER['REMOTE_ADDR'];
    $motto = $config['client']['motto'];
    $query = mysql_query("INSERT INTO `users` (`username`, `refer`, `password`, `mail`, `ip_last`, `ip_reg`, `motto`) VALUES(`$u`, `$r`, `$p`, `$m`, `$ip`, `$ip`, `$motto`);");
    if(!$query) {
        die(mysql_error());
    }
}

Error:
XnJ7BC.png
 

brsy

nah mang
May 12, 2011
1,530
272
PHP:
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>{sitename} - Register</title>
       
        <script type="text/javascript" src="{style}/js/visual.js"></script>
        <script type="text/javascript" src="{style}/js/common.js"></script>
        <link rel="stylesheet" href="{style}/styles/common.css" type="text/css">
        <link rel="stylesheet" href="{style}/styles/embedregistration.css" type="text/css">
       
        <script type="text/javascript">
            document.habboLoggedIn = true;
            var habboName = null;
            var habboId = null;
            var habboReqPath = "";
            var habboStaticFilePath = "{style}";
            var habboImagerUrl = "http://www.habbo.com/habbo-imaging/";
            var habboPartner = "";
            var habboDefaultClientPopupUrl = "{www}/client";
            window.name = "habboMain";
            if (typeof HabboClient != "undefined") {
                HabboClient.windowName = "client";
                HabboClient.maximizeWindow = true;
            }
        </script>
       
        <style type="text/css">
            input[type="submit"], input[type="button"] {
                background: url('{style}/images/reg_btn.png') top;
                font: bold 13px arial,sans-serif;
                line-height: 25px;
                color: black;
                height: 25px;
                width: 99px;
                border: 0;
            }
            input[type="submit"]:hover, input[type="button"]:hover {
                background-position: bottom;
                cursor: pointer;
            }
        </style>
       
        <!--[if IE 8]>
            <link rel="stylesheet" href="{style}/styles/ie8.css" type="text/css">
        <![endif]-->
        <!--[if lt IE 8]>
            <link rel="stylesheet" href="{style}/styles/ie.css" type="text/css" />
        <![endif]-->
        <!--[if lt IE 7]>
            <link rel="stylesheet" href="{style}/styles/ie6.css" type="text/css" />
            <script type="text/javascript" src="{style}/js/pngfix.js"></script>
            <script type="text/javascript">
                try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}
            </script>
            <style type="text/css">
                body { behavior: url({style}/js/csshover.htc); }
            </style>
        <![endif]-->
    </head>
   
    <body>
   
        <div id="overlay"></div>
        <div id="container" class="phase-0" style="margin-top: 10px;">
            <div class="register-container clearfix">
                <div class="register-header">Register at {sitename} Hotel</div>
                <div id="register-content">
                    <div id="subheader">Fill out the form below to register here!</div>
                    <div class="register-container-bottom-end register-content clearfix">
                        <div id="auth-providers" class="auth-providers">
                            <ul>
                                <li class="facebook"><a href="#" class="provider"></a></li>
                                <li class="twitter"><a href="#" class="provider"></a></li>
                                <li class="google"><a href="#" class="provider"></a></li>
                                <li class="hyves"><a href="#" class="provider"></a></li>
                                <li class="myspace"><a href="#" class="provider"></a></li>
                                <li class="windowslive"><a href="#" class="provider"></a></li>
                                <li class="yahoo"><a href="#" class="provider"></a></li>
                            </ul>
                        </div>
                        <div id="register-page" style="clear: left" class="phase-0 clearfix">
                            <div class="phase-0">
                                <form method="post" id="phase-0-form">
                                    <div id="error-messages-container">
                                        <?php
                                        if(isset($_POST['reg_submit'])) {
                                            $p = mysql_real_escape_string(htmlentities($_POST['reg_password']));
                                            $rp = mysql_real_escape_string(htmlentities($_POST['reg_rep_password']));
                                            $m = mysql_real_escape_string(htmlentities($_POST['reg_email']));
                                            $r = mysql_real_escape_string(htmlentities($_POST['reg_refer']));
                                            $u = mysql_real_escape_string(htmlentities($_POST['reg_username']));
                                            $fp = md5($p);
                                            $username = mysql_num_rows(mysql_query("SELECT * FROM users WHERE username = '" . $u . "' LIMIT 1"));
                                       
                                            if(empty($p) || empty($rp) || empty($m) || empty($u)) {
                                                $error = "Please enter all of the required fields.";
                                            }
                                            if(strlen($u) > 32 || strlen($u) < 4) {
                                                $error = "Usernames should have 4 - 20 characters.";
                                            }
                                            if(preg_match('/[^a-z,-.-0-9]/i', $u)) {
                                                $error = "Usernames can only have numbers, letters, commas, periods, and hyphens.";
                                            }
                                            if($username > 0) {
                                                $error = "The username <b>".$u."</b> is already taken.";
                                            }
                                            if(strlen($p) <= '6' || strlen($p) >= '35') {
                                                $error = "Passwords must have inbetween 7 and 32 characters.";
                                            }
                                            if($p != $rp) {
                                                $error = "The password you have repeated does not match the one you have entered.";
                                            }
                                                if(isset($error)) {
                                                    echo '<div class="error-messages-holder"><ul><li><p class="error-message">'.$error.'</p></li></ul></div>';
                                                }
                                                if(!isset($error)) {
                                                    $ip = $_SERVER['REMOTE_ADDR'];
                                                    $motto = $config['client']['motto'];
                                                    $query = mysql_query("INSERT INTO `users` (`username`, `refer`, `password`, `mail`, `ip_last`, `ip_reg`, `motto`) VALUES(`$u`, `$r`, `$fp`, `$m`, `$ip`, `$ip`, `$motto`);");
                                                        if(!$query) {
                                                            die(mysql_error());
                                                        }
                                                }
                                        }
                                        ?>
                                    </div>
                                    <div id="name-field-container">
                                        <div class="field field-habbo-name">
                                            <label for="habbo-name"><b>Username</b></label>
                                            <input type="text" id="habbo-name" size="35" value="" name="reg_username" class="text-field" maxlength="32">
                                        </div>
                                    </div>
                                    <div class="field field-password">
                                        <label for="password"><b>Password</b></label>
                                        <input type="password" id="password" size="35" name="reg_password" value="" class="password-field" maxlength="32">
                                    </div>
                                    <div class="field field-password2">
                                        <label for="password2"><b>Confirm Password</b></label>
                                        <input type="password" id="password2" size="35" name="reg_rep_password" value="" class="password-field" maxlength="32">
                                    </div>
                                    <div class="field field-email">
                                        <label for="email"><b>Email Address</b></label>
                                        <input type="text" id="email" size="35" name="reg_email" value="" class="text-field" maxlength="48">
                                    </div>
                                    <div class="field field-seckey">
                                        <label for="seckey"><b>Referral</b></label>
                                        <input type="password" id="refer" size="35" name="reg_refer" value="" class="text-field" maxlength="32">
                                    </div>
                                    <input type="submit" value="Register" name="reg_submit">
                                    <input type="button" value="Cancel" onclick="location.href='{www}/'" style="float:right;margin-right:12px;">
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="register-container-bottom"></div>
                <!--[if lt IE 7]>
                    <script type="text/javascript">
                        Pngfix.doPngImageFix();
                    </script>
                <![endif]-->
            </div>
        </div>
        <script type="text/javascript">
            HabboView.run();
        </script>
   
    </body>
</html>
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
Code is pretty sloppy.

  • Good practice IMO: PHP goes on top of HTML tags
  • How you handle errors - Not really functional.
The query fails.

I'd try and do this as the query: "INSERT INTO `users` (username, refer, password, mail, ip_last, ip_reg, motto) VALUES(`$u`, `$r`, `$fp`, `$m`, `$ip`, `$ip`, `$motto`)"
 

brsy

nah mang
May 12, 2011
1,530
272
Thanks Kryptos. In regards to the sloppiness of the code, I know. I just realised I can put the code at the top, leave an open { bracket, then put PHP tags again to close it.
 
Status
Not open for further replies.

Users who are viewing this thread

Top