Results 1 to 19 of 19

Thread: Problem writing to the database - php

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    32

    Problem writing to the database - php

    Code:
    <html>
    <head></head>
    <body><form method="post" action="register.php">
    
    
    
    Name: <input type="text" name="name">         <br>
    
    Age:</td><td> <input type="text" name="age">  <br>
    
    Country: </td><td><input type="text" name="country">  <br>
    
    Email: </td><td><input type="text" name="email"> <br>
    
    Username: <input type="text" name="username">             <br>
    
    Password:</td><td> <input type="text" name="password">   <br>
    
    Gender: </td><td><input type="text" name="gender"> <br>
    
    
    
    
    <input type="Submit" name="submit" value="Registrer"><br>
    </form>
    
    <?
    IF ("$submit") {
    
    $host = "*";
    $user = "*";
    $pass = "*";
    
    if (!$db = @mysql_connect("$host","$user", "$pass")) {
    $db_error = "couldn't connect.";
    do_error($db_error);
    }
    
    
    {mysql_pconnect ("$host","$user");
    }
    mysql_select_db("hacker");
    
    $sql = "insert into user(name, age, country, email, username, password, gender) values('$name', '$age', '$country', '$email', '$username', '$password', '$gender')";
    
    
    $result = mysql_query($sql);
    $ID = mysql_insert_id();
    Print("Konto opprettet!");
    }
    ?>
    
    </body>
    </html>
    This thingy dosen't seem to write to the database, but it does connect.
    Any ideas?

  2. #2
    scoutt
    Guest
    well,
    Code:
    {mysql_pconnect ("$host","$user");
    }
    mysql_select_db("hacker");
    
    $sql = ("insert into user(name, age, country, email, username, password, gender) values('$name', '$age', '$country', '$email', '$username', '$password', '$gender')");
    
    
    $result = mysql_query($sql);
    $ID = mysql_insert_id();
    Print("Konto opprettet!");
    }
    ?>
    why do you have those brackets (bold) there? and you forgot to add some more brackets see bold, try that and see what you get.

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    32
    if dosn't seem to work..


    Could it have anything to do with the config of the database?

  4. #4
    scoutt
    Guest
    ok did you add { or ( you need to add the latter to the $sql statement. are you getting any errors? now you said it connects just fine but it just won't save anything? am I right.

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    32
    I added ( and ) , cause when I added the { i got:
    Parse error: parse error in /public_html/register.php on line 44


    Thats this line: $sql = "insert into user(name, age....

    Your right, it does connect, but it dosn't save anything...

  6. #6
    scoutt
    Guest
    you can try to do it this way.
    Code:
    mysql_pconnect($host, $user, $pass) or die("error opening the MySQL server"); 
    mysql_select_db("hacker") or die("error opening the MySQL Database"); 
    $sql_insert = ("insert into user(name, age, country, email, username, password, gender) values('$name', '$age', '$country', '$email', '$username', '$password', '$gender')");
    $result = mysql_query($sql_insert);
    $ID = mysql_insert_id();
    Print("Konto opprettet!");
    
    //for debugging
    {
    print("$sql_insert");
    }
    and take out (delete) this
    Code:
    if (!$db = @mysql_connect("$host","$user", "$pass")) {
    $db_error = "couldn't connect.";
    do_error($db_error);
    }
    try that and see what you get. can you check you error.log and see if/what error you have when you did this. if this doesn't work i one more thing.
    change the form action to this
    action="<? echo $PHP_SELF ?>">

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    32
    Access denied for user: '[email protected]' (Using password: YES)

    Why? I've no idea!
    Guess it's something to do with the config of the database?!

    Just gotta keep trying til I get it right i guess.
    Thanx for your help! =)

  8. #8
    scoutt
    Guest
    yup I would talk to the server guys about that.

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    32
    ok, now i got access.
    But, guess what.. still nothing happens.

    I think I'll just start all over again.

  10. #10
    scoutt
    Guest
    so what error do you receive now?

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    32
    Ohh, i got it to work!!!

    Love you guys!!!

    *happy boy*

    This is what i love about programing!


  12. #12
    scoutt
    Guest
    cool, but what was the problem. let yus know who or if you fixed it.

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    32
    I not sure why, but i changed a field in the database from int to char. But it was supposed to hold figures so..

  14. #14

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    32
    Btw..

    I'm trying to make a little game. Should I a) have all the data in one huge database or b) divide it into smaller ones?

  15. #15
    scoutt
    Guest
    that would be totally up to you. if you want to seperate it so you know where everything is then fine.

    But if you do split it up and you have a lot and I mean a lot of information then it would improve the access time, as opposed to everything stuffed in one table.

    but if you don't have a lot of information than I wouldn't worry about it.

    what other info would you have execpt wha tyou have here?

  16. #16

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    32
    I was thinking of haveing this:
    money, points, rank, bytes, protection, and skills.

    Would also have log in screen, attack code and a formula of creation bytes ever 10 minutes or so..
    But that shouldn't mean more stuff in the database?

  17. #17
    scoutt
    Guest
    Originally posted by Mobic
    I was thinking of haveing this:
    money, points, rank, bytes, protection, and skills.

    Would also have log in screen, attack code and a formula of creation bytes ever 10 minutes or so..
    But that shouldn't mean more stuff in the database?
    if those are the only things in the database I wouldn't worry about it. but if you have stuff under these then ya make more tables.

    by rank do you mean like a top score. I would put that info in another table as it would opnly be called at the end or whenever.

  18. #18

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    32
    Ok, thanks.

    Rank = their current rank while their playing the game, with the possibility to log on later and continue..

    If multiple users should be able to login and use the same sites but with different values in the variables, should i then use sessions?
    Last edited by Mobic; Aug 14th, 2001 at 01:12 PM.

  19. #19
    scoutt
    Guest
    that wouldn't hurt. make sure the server is setup to use sessions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width