SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy No Errors(?) + Not working; //Register script

    Okay I have tested that all the values are working from form on another page. The thing just isn't updating db.. why is this?

    PHP Code:
    <?php

    require 'config.php';

    $result mysql_query('SELECT * FROM users') or die('Could not gather info: ' mysql_error());


    if (isset(
    $_POST['submit'])) 
        {
        
    $username $_POST['username'];
        
    $password sha1($_POST['password']);
        
    $ip $_SERVER['REMOTE_ADDR'];
        
    $registered date("F j, Y, g:i a");  
        
        
    //print_r($_POST);
        //echo $ip, $registered;
        
    $query 'INSERT INTO users (username, password, registration_date, user_ip) VALUES('.$username.', '.$password.', '.$registered.', '.$ip.')';
        
    $result mysql_query($query);
        
    /*else 
            { 
            echo 'This email adress has already been registered.'; 
            }*/ 
        

        else 
        {
            echo 
    'Die Hacking Attempt!';
        }
        
    //echo $username, $password, $ip, $registered;
    ?>
    Im also looking to secure the password a little bit better than a simple sha1.
    <3php && SitePoint ?>

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Have you done a or die(mysql_error()) on the $result query and what does the sql look like when you print it?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I print the array info... it looks like

    Array ( [username] => name [password] => pass [password2] => pass [submit] => submit ) 127.0.0.1June 9, 2007, 3:19 pm

    and thats using the lines
    print_r($_POST);
    echo $ip, $registered;
    <3php && SitePoint ?>

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    sorry, I meant on the query line:
    PHP Code:
    $result mysql_query($query) or die(mysql_error()); 
    If that doesnt turn anything up, check the field types in the sql table itself because if you are inerting the registered date into a date field it is in the wrong format.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where did you connect to the database?
    Where did you select the database?
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  6. #6
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, spikeZ I will check field types; and check for erros.

    Quote Originally Posted by byron3@earthlink View Post
    Where did you connect to the database?
    Where did you select the database?
    in config.php
    PHP Code:
    <?php
    $dbconnec 
    mysql_connect('localhost''root''') or die('Could not connect to database');
    $dbselect mysql_select_db('tld4us') or die('Could not select database');
    ?>
    <3php && SitePoint ?>

  7. #7
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you make those variables global?
    Ever heard of scope?
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  8. #8
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No please explain? I have been wondering because I'm going to need ppl to stay logged in while they visit various parts of a website.

    spikeZ look at the problem with query

    Problem with query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '9, 2007, 3:36 pm, 127.0.0.1)' at line 1

    field: registration_date type: datetime; no other special attributes.
    <3php && SitePoint ?>

  9. #9
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Datetime expects the date format YYYY-MM-DD not a humanised form.
    You can manipulate the date as you get it from the database.
    You can simply use NOW() in your query to put the date time into the correct format
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  10. #10
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again spikeZ!
    I can't find now() in the php manual.
    What would I put inside of the brackets?

    I should mention that it needs to work for php 4.4.4
    <3php && SitePoint ?>

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Your query would look like:
    PHP Code:
     $query "INSERT INTO users (username, password, registration_date, user_ip) VALUES('".$username."', '".$password."', NOW(), '".$ip."')"

        
    $result mysql_query($query); 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #12
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OH, okay, I didn't realize it was a specific thing to mysql.
    <3php && SitePoint ?>

  13. #13
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  14. #14
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is how information is being put into db

    user_id: 1 username: name password: 9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684 date&time: 2007-06-09 16:18:52 ip adress: 127

    For 127.0.0.1 will it always show ip as 127?

    It seems to be working.. except when I access the script not using the form it gives me an unexpected $end, even though all brackets are closed.

    Here is the new code:
    PHP Code:
    <?php

    require 'config.php';


    $result mysql_query('SELECT * FROM users') or die('Could not gather info: ' mysql_error());


    if (isset(
    $_POST['submit'])) 
        {
        
    $username $_POST['username'];
        
    $password sha1($_POST['password']);
        
    $password2 sha1($_POST['password2']);
        
    $ip $_SERVER['REMOTE_ADDR'];
        
    $registered date("F j, Y, g:i a");  
        
            if (
    $password == $password2
            {
            
    $query $query "INSERT INTO users (username, password, registration_date, user_ip) VALUES('".$username."', '".$password."', NOW(), '".$ip."')";
            
    $result mysql_query($query) or die('Problem with query: ' mysql_error());
            }
        
        }
        
        else 
        {
        echo 
    'Die Hacking Attempt!';
        }
            
    ?>
    I will add some validation stuff to it later.
    <3php && SitePoint ?>

  15. #15
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    The IP address it is picking up is your Localhost address which is always 127.0.0.1. Once the script is on a server it should be ok and pick up the users IP addy.

    As for the brackets it must be something other than the snippet you posted as they do indeed all balance.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  16. #16
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is the entire code of the file. I am assuming it is something to do with WAMP or my comp where it is caching or something.
    <3php && SitePoint ?>


Bookmarks

Posting Permissions

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