Help with my website

Results 1 to 2 of 2
  1. #1
    Account Upgraded | Title Enabled! Wokki is offline
    MemberRank
    Aug 2008 Join Date
    FinlandLocation
    724Posts

    Help with my website

    Yesterday I started working on my custom FlyFF website, which is still totally under work. I've got the skin 100% ready, but I am still missing the scripts.

    So, I would like to know what is wrong in my registeration script.

    Code:
    <?php include("ylaosa.php") ?>
    <h1>Register</h1>
    <?php
    if(isset($_POST['reg_user']) && isset($_POST['reg_password']) && isset($_POST['reg_check'])){
    
       $text = "";
    
       $tunnus = get_magic_quotes_gpc() ? $_POST['reg_user'] : mysql_real_escape_string($_POST['reg_user']);
       $salasana = get_magic_quotes_gpc() ? $_POST['reg_password'] : mysql_real_escape_string($_POST
    
    ['reg_password']);
       $varmistus = get_magic_quotes_gpc() ? $_POST['reg_check'] : mysql_real_escape_string($_POST
    
    ['reg_check']);
    
       $sql = mysql_query("SELECT COUNT(*) AS yht FROM {$tbl_accounts} WHERE username = '".$username."'",$lnk);
       $sql = mysql_fetch_assoc($sql);
       $yht = $sql['yht'];
    
       if($yht != 0)
          $text .= "This username is in use.<br />\n";
    
       if(strlen($username) < 3)
          $text .= "Username is too short. Minimum leght is 3 characters.<br />\n";
    
       if(strlen($password) < 3)
          $text .= "Password is too short. Minimum leght is 3 characters.<br />\n";
    
       if($password != $check)
          $text .= "Passwords did not match.<br />\n";
    
       if($text == ""){
    
          $sql = mysql_query("INSERT INTO {$tbl_accounts} (username,password) VALUES ('".$username."','".md5
    
    ($password)."')",$lnk);
          if(!$sql || mysql_affected_rows($lnk) < 1)
             $text = "SQL-lauseessa virhe.<br />\n";
          else
             $text = "Registeration succesful!<br />";
       }
       echo $text;
    
    }
    ?>
       <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
         <table width="0%" border="0">
           <tr>
             <td>Username:</td>
             <td><input name="reg_user" type="text" size="15" maxlength="20"
             value="<?php echo isset($_POST['reg_user']) ? $_POST['reg_user'] : ""; ?>" /></td>
           </tr>
           <tr>
             <td>Password:</td>
             <td><input name="reg_password" type="password" size="15" maxlength="20" /></td>
           </tr>
           <tr>
             <td>Password:</td>
             <td><input name="reg_check" type="password" size="15" maxlength="20" /></td>
           </tr>
           <tr>
             <td colspan="2"><input type="submit" value="Register" /></td>
           </tr>
         </table>
       </form>
    <a href="index.php">Home</a>
    
    <?php include("alaosa.php") ?>
    So this is how it looks at the moment.

    When I try to use it, I get warning message:
    "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in register.php on line 13"

    I dont know why it gives warning about line 13, when the line 13 is empty.

    Anyone know how can I fix this and get it ready to be in use?
    Last edited by Wokki; 22-08-09 at 09:09 AM.


  2. #2
    Account Upgraded | Title Enabled! BBim is offline
    MemberRank
    Sep 2008 Join Date
    127.0.0.1Location
    1,110Posts

    Re: Help with my website

    I think its line 13 counting after <?php since the rest is just html.
    The error, from what I know is because of a wrong sql query, so check it on navicat or phpmyadmin or something.
    Also, I think you should use this:
    Code:
    function removeQuotes($txt)
    {
    	$txt = (get_magic_quotes_gpc()) ? stripslashes($txt) : $txt;
    	return mysql_real_escape_string($txt);
    }
    
    
    $tunnus = $_POST['reg_user'];
    Becausee magic_quotes isnt as good as mysql escape string, so you remove them and use mysql's one.



Advertisement