Jump to content

Confused, A hand please?


GetReady

Recommended Posts

Hi, i made a registration page in php, Only problem is its not submitting anything to the database nor throwing back an errors. I'm confused as to why, the code is below any help will be appreciated thanks

 

** server.php holds the database info i.e

 

<?php 
///Server Info
$dbhost = "localhost";
$dbuser = "*****";
$dbpass = "******";
$dbname = "****";
$conn = mysql_connect($dbhost,$dbuser,$dbpass)
or die();
mysql_select_db($dbname);
?>

 

Registration page in question;

 <?php
require_once('check.php');
session_start();
$name = $_SESSION['name'];
require_once('server.php');
require_once('stats.php');
    if($_POST) {
        function VisitorIP()
    { 
    if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $TheIp=$_SERVER['HTTP_X_FORWARDED_FOR'];
    else $TheIp=$_SERVER['REMOTE_ADDR'];

    return trim($TheIp);
    }
        $ipaddress = VisitorIP();
        $name = $_POST['username'];
        $namelength = strlen($name);
        $email = $_POST['email'];
        $password = $_POST['password'];
        $passwordlength = strlen($password);
        $confirm = $_POST['confirm'];    
        if($namelength < 3){
            
           $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: Your username must be at least 3 characters!</span></div>";
           echo $error1;
          } 
        elseif($passwordlength < 6) {
            $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: Password must be at least 6 characters long!</span></div>";
            echo $error1;
        }
        elseif($email == "") {
            $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: You must enter an email address!</span></div>";
            echo $error1;
          }   
        elseif($password != $confirm) {
        $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: Passwords do not match!</span></div>";
        echo $error1;
          } else {
                include("server.php");
            $query = sprintf("SELECT COUNT(id) FROM players WHERE UPPER(name) = UPPER('%s')",
                mysql_real_escape_string($_POST['username']));
            $result = mysql_query($query);
            list($count) = mysql_fetch_row($result);
            if($count >= 1) { 
$error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: that username is taken.</span></div>";
echo $error1;

        } else {
                $query1 = sprintf("INSERT INTO players(name,password,email,ip_address) VALUES ('%s','%s', '$email','$ipaddress');",
                    mysql_real_escape_string($_POST['username']),
                    mysql_real_escape_string(md5($password)));
                mysql_query($query1);
            
$error1="<div class='text1' style='background-color:#FF0;'><span style='color:#390'>Congratulations, you registered successfully!</span></div>";
echo $error1;

            }    
         }
    }
?>

Link to comment
Share on other sites

The following is 100% connected to the database as it says if a name is in use.... yet wont let you register;

 

Really starting to hurt my head wondering as to why i just cannot see it, please any help will be great thanks.

<?php
    if($_POST) {
        function VisitorIP()
    { 
    if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $TheIp=$_SERVER['HTTP_X_FORWARDED_FOR'];
    else $TheIp=$_SERVER['REMOTE_ADDR'];

    return trim($TheIp);
    }
        $ipaddress = VisitorIP();
        $name = $_POST['username'];
        $namelength = strlen($name);
        $email = $_POST['email'];
        $password = $_POST['password'];
        $passwordlength = strlen($password);
        $confirm = $_POST['confirm'];    
        if($namelength < 3){
            
           $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: Your username must be at least 3 characters!</span></div>";
           echo $error1;
          } 
        elseif($passwordlength < 6) {
            $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: Password must be at least 6 characters long!</span></div>";
            echo $error1;
        }
        elseif($email == "") {
            $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: You must enter an email address!</span></div>";
            echo $error1;
          }   
        elseif($password != $confirm) {
        $error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: Passwords do not match!</span></div>";
        echo $error1;
          } else {
                include("server.php");
            $query = sprintf("SELECT COUNT(id) FROM players WHERE UPPER(name) = UPPER('%s')",
                mysql_real_escape_string($_POST['username']));
            $result = mysql_query($query);
            list($count) = mysql_fetch_row($result);
            if($count >= 1) { 
$error1="<div class='text1' style='background-color:#FF0;'><span style='color:red'>Error: that username is taken.</span></div>";
echo $error1;

        } else {
                $query1 = sprintf("INSERT INTO players(name,password,email,ip_address) VALUES ('%s','%s', '$email','$ipaddress');",
                    mysql_real_escape_string($_POST['username']),
                    mysql_real_escape_string(md5($password)));
                mysql_query($query1);
            
$error1="<div class='text1' style='background-color:#FF0;'><span style='color:#390'>Congratulations, you registered successfully!</span></div>";
echo $error1;

            }    
         }
    }
?>

Link to comment
Share on other sites

I do get when registering a name not currently in the database;

 

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\Program Files\EasyPHP-5.3.3\www\htdocs\register.php on line 174

Congratulations, you registered successfully!

 

Line 174 in dreamweaver is the:    mysql_real_escape_string($_POST['username']),

 

Rather odd.

Link to comment
Share on other sites

Yea, actual sql below.... I have absolutely no clue why it's not working  :shrug:

--
-- Table structure for table `players`
--

CREATE TABLE IF NOT EXISTS `players` (
  `id` int(9) NOT NULL AUTO_INCREMENT,
  `name` varchar(21) NOT NULL,
  `password` varchar(60) NOT NULL,
  `email` varchar(60) NOT NULL,
  `ip_address` varchar(30) NOT NULL,
  `last_login` timestamp NULL DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL,
  `in_guild` tinyint(1) NOT NULL,
  `score` int(9) NOT NULL,
  `actual_score` int(9) NOT NULL,
  `attack` int(9) NOT NULL,
  `armor` int(9) NOT NULL,
  `magic` int(9) NOT NULL,
  `resist` int(9) NOT NULL,
  `gold` bigint(12) NOT NULL,
  `bank_gold` bigint(12) NOT NULL,
  `bank_deposits` int(11) NOT NULL DEFAULT '2',
  `class` varchar(20) NOT NULL,
  `energy` int(9) NOT NULL,
  `energy_regen` tinyint(3) NOT NULL DEFAULT '10',
  `age` bigint(14) NOT NULL,
  `sex` varchar(20) NOT NULL,
  `rank` varchar(20) NOT NULL,
  `experience` int(9) NOT NULL,
  `level` tinyint(1) NOT NULL,
  `admin` tinyint(1) NOT NULL,
  `location` varchar(55) NOT NULL DEFAULT 'Caldera',
  `room` int(11) NOT NULL DEFAULT '5',
  `x_loc` int(4) NOT NULL DEFAULT '4',
  `y_loc` int(4) NOT NULL DEFAULT '3',
  `donator` tinyint(1) NOT NULL,
  `subscriber` tinyint(1) NOT NULL,
  `points` bigint(12) NOT NULL,
  `income` int(11) NOT NULL DEFAULT '50',
  `gold_stolen` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=124561 ;

Link to comment
Share on other sites

I have just split up your code a bit (inefficient, but to have a more clear view)

 

$name = $_POST['username'];
$cleaned_name = mysql_real_escape_string($name);
$query = sprintf("SELECT COUNT(id) FROM players WHERE UPPER(name) = UPPER(%s)", $cleaned_name);

 

Would this be of any help? I also removed the ' ' from the %s ( http://msdn.microsoft.com/en-us/library/ms180055.aspx)

 

- edit: hehe awesome where can I play the game I see attack and gold  ::)

Link to comment
Share on other sites

Thanks, I'll give that a look, may just be worth me re coding the registration page... worked last time i tested it guess i screwed something up (dammit not keeping back ups!) and i haven't released it as of yet, doing the last stretch of testing, bug fixes etc at this current time... probably be another week or so before we go live, if your interested I'll message you when it's up and running.

Link to comment
Share on other sites

Thanks, I'll give that a look, may just be worth me re coding the registration page... worked last time i tested it guess i screwed something up (dammit not keeping back ups!) and i haven't released it as of yet, doing the last stretch of testing, bug fixes etc at this current time... probably be another week or so before we go live, if your interested I'll message you when it's up and running.

hehe sure do : ) I love to see php in action! (certainly if i could have been of any help with it) But i am pretty sure those ' ' are wrong.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.