1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. To chat with the GameOgre community, you need to have at least 15 posts. Once you have the 15 posts, post at Become A New Ogre
    Dismiss Notice

why code don't work?

Discussion in 'Online Game Development' started by rtkwar, Nov 27, 2011.

Thread Status:
Not open for further replies.
  1. rtkwar

    rtkwar Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Credit:
    - 54.14

    imake 2 php file:

    index.php

    register.php
    but always iback to index.php
    why ican't insert information in datebase?

    itried to edit register.php
    but thats don't work too

    this files work good on my apache server on my pc but when iupload this files to my web site thats not work ican't insert information
    isure from table name and all other information and thats info

    table.sql
    when itry insert information ifind username and password and mail empty

    whats wrong here?





     
  2. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21
    what kind of error message do you get? if you do get an error message
     
    Last edited by a moderator: Nov 29, 2011
  3. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21
    I tried to transcribe it my way, but it can't seem to find anything wrong with it:

    Code:
    /*SQL CONNECTION*/
    $con = mysql_connect("$myserver","$myname","$mypassword");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    else {
    
    //DATABASE SELECTION
    $selector = mysql_select_db($mydatabase, $con);
    if (!$selector)
    {
      die('Could not select database: ' . mysql_error());
    }
    else {
    
    
    mysql_query("insert into accounts (username, password, mail) values
    ('$user5', '$password5', '$mail5')");
    
    }
    }
    
    OK questiontime!

    first question: Is the password, username and database name correct?
    second question: Does your host allow php includes?
     
  4. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21
    third question: has the table been created properly?

    Code:
    CREATE TABLE accounts (
    id int(11) NOT NULL auto_increment,
    PRIMARY KEY (id),
    username varchar(255) NOT NULL default '0',
    password varchar(255) NOT NULL default 'noname',
    mail varchar(255) NOT NULL default 'nomail'
    ) TYPE=MyISAM; 
    
    don't put a comma at the end of the last column to be created into the table! Perhaps that is what went wrong. Also you write no null, but your default is null!
     
    Last edited by a moderator: Nov 29, 2011
  5. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21
    just out of curiosity! I see the top level domain is .ae of your page

    You have a domain in the United Arab Emirates, even though your Egyptian?
     
  6. rtkwar

    rtkwar Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Credit:
    - 54.14
    reply

    idon't get any error message but nothing insert in datebase only id and other information empty
    datebase look like this
    id - username - password - mail
    1 -(empty)- (empty) - (empty)

    but when iuse this code:
    iback to index.php and nothing insert

    yes isure from this

    idon't know but ithink thi because ar.php include all arabic words and its work good when i include it in index.php
    thats my host Free Web Hosting with PHP, MySQL, Email Sending, No Ads

    ihave 2 accounts on this website one from them work good (world-war2) but other website code don't work with it
    yes

    thats not my website thats Tribalwars website:
    Tribal Wars - The browser game english version
    Ø*رب القبائل arabic verion


    Idon't know but ithink problem in form
     
  7. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21
    that is one possibility!

    You will have to show me your html form and the post part of your php script. I'm assuming you're using post and not get for your registration.

    Maybe the reference to the name in the form doesn't match with the variable name of the post or get

    also I wonder why you use php inside your html table. Why do you want to have blank cells in your table when the sql connection fails? It doesn't make sense!

    You do have a post part of your script, right? I know it is a silly question, because it's like wondering why your computer doesn't work, when you forgot to plug it into the socket.
     
  8. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21
    OK the id is the primary key, then at least we've established that sql works.

    So it must be a misreference in the variable name (from html form to post part of script), or you do not post.

    You'll have to show me the html form and the part in the script from the isset command onwards, to make certain which one it is.
     
    Last edited by a moderator: Nov 29, 2011
  9. rtkwar

    rtkwar Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Credit:
    - 54.14
    all code

    ok thats all files
    Index.php


    register.php

    config.php
     
    Last edited by a moderator: Nov 29, 2011
  10. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21
    yeah I don't see you post!

    Where is the ISSET command?! It's nowhere to be found.

    You don't use ISSET, instead you use function "click" for php, like you use a javascript function.

    Remember php is serverside, not clientside like javascript!

    The server needs to get the variable from the user computer some way, and that way is the input post and isset commands.
     
    Last edited by a moderator: Dec 2, 2011
  11. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21
    Code:
    if (isset($_POST["username5"]) && isset($_POST["password5"]){
    
    filter_var($_POST["username5"], FILTER_SANITIZE_STRING);
    filter_var($_POST["password5"], FILTER_SANITIZE_STRING);
    
    if(!filter_has_var(INPUT_POST, "password5")){
    if(!filter_has_var(INPUT_POST, "username5")){
    $password5 = $_POST["password5"];
    $username5 = $_POST["username5"];
    
    $query="insert into accounts (username,password,mail) values
    ('$user5','$password5','$mail5')";
    
    
    
    now I left out mail5, but you should get the general idea
     
  12. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21
    If that ^ still doesn't solve the problem, and you do post, then your sql database is corrupt (that may be due to version differences (between sql and php), I learned this the hard way myself since wednesday).
     
    Last edited by a moderator: Dec 2, 2011
  13. rtkwar

    rtkwar Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Credit:
    - 54.14
    thank you very much thats work with me now , but why in my other web site my code work good without Isset or $_Post?
     
  14. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21
    perhaps because it is on the same computer, hence client side
     
  15. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21
    One other really important thing!

    And this is important for your website's security!

    Whenever you GET or POST a variable, make sure that variable is filtered! Variables that are obtained with GET or POST are what we call external variables. It is really important that these are filtered, or else you are vulnerable to what hackers call an sql injection.

    Basically what these hackers are doing when they notice that an external variable isn't filtered and sanitized for html code or php or sql commands, is that they can post such commands and hence corrupt your database or worse hack into your database and obtain things like passwords, usernames and whatever else is in there.

    You really don't want that to happen!

    Why do I mention this? Because in the include of the config file, I don't see you use a filter.

    See this page for some examples:

    http://www.w3schools.com/php/php_ref_filter.asp
     
    Last edited by a moderator: Dec 6, 2011
  16. rtkwar

    rtkwar Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Credit:
    - 54.14
    iwant know if this filter work with php5 only?

     
  17. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21
    It should work with every kind of version of php, I think version 4 has the same filter functions as version 5, though you would have to check the manual to be certain.
     
  18. rtkwar

    rtkwar Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Credit:
    - 54.14
    Ithink filter don't work with php4 itry example from w3school and not work ithink iwill use regular expression
     
  19. shugo

    shugo Active Member Ogre Veteran

    Messages:
    2,092
    Likes Received:
    10
    Trophy Points:
    38
    Credit:
    14,282.21

    that's weird. Are you sure you're using the filter the way you should?

    regular expressions are not filters! You'd still be vulnerable to sql injection!
     
  20. rtkwar

    rtkwar Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    16
    Credit:
    - 54.14
    I copy and paste code from w3school for sure if filters work with php4 but iget error
     
Thread Status:
Not open for further replies.

Share This Page