SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: php code mysql

  1. #1
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php code mysql

    Hello Everyone, I am new to php so i am looking for some advice from you guys.
    I am wanting building a login system in Flash for my website. So every new user i can organize and store information into the mysql database.
    The database and table i have already created. My table has 4 coulumns id, username, password and email.
    I have two ActionScript 3.0. fla files login and register i have a general idea how to code these files.
    However, when it come's to the php file i am struggling . My code is below i know it probably has errors in because i am complete novice to php. I would appreciate it if you could highlight the mistakes and tell me if there is anything missing in the file that should be there. I don't expect you to do all the work for me im just some advice. Thanks.



    Code PHP:
    <?php 
     
    //Declare variables
    $username = $_POST['username']; 
    $password = $_POST['password'];
    //
    //mysql connection variables
    $email = $_Post['email'];
    $username = $_POST['username']; 
    $password = $_POST['password']; 
    $age = $_POST['age'];
    $country = $_POST['location']
    //
     
    //connects to database
    $link = mysql_connect("localhost","example_database","password") or die (mysql_error());
    mysql_select_db("example_users") or die(mysql_error());
    ?>
     
    $email = $_Post['email'];
    $username = $_POST['username']; 
    $password = $_POST['password']; 
    $age = $_POST['age'];
    $country = $_POST['location']
     
     
    //collects data from table
    $data = mysql_query("SELECT * FROM users");
    $results = mysql_query($query)
    or die(mysql_error());
     
    //put users info into the $info array
    $info = mysql_fetch_array( $data ))
     
    $userbio = $data["name"];
     
    echo "systemResult=$userbio";
     
     
    } 
     
    } else {
     
    echo "systemResult=The login detail dont much our records
     
    }
    ?>
    Last edited by TechnoBear; Dec 15, 2012 at 08:45. Reason: PHP code tags added

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    266
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Try this code. Replace the connection data (in mysql_connect() ) and the name of the columns with your data.
    Code:
    <?php 
    //Declare variables
    $email = $_Post['email'];
    $username = $_POST['username']; 
    $password = $_POST['password']; 
    $age = $_POST['age'];
    $country = $_POST['location'];
     
    //connects to database
    $link = mysql_connect("localhost", "user_name", "password") or die (mysql_error());
    mysql_select_db("database_name") or die(mysql_error());
     
     
    //collects data from table
    $data = mysql_query("SELECT * FROM users WHERE col_username='$username' AND col_password='$password'");
    if (mysql_num_rows($data) == 0) {
      echo "systemResult=The login detail dont much our records";
    }
    else {
      while ($row = mysql_fetch_assoc($data)) {
        $userbio = $row["name"];
        echo "systemResult=$userbio";
      }
    }
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2011
    Location
    Portland
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also be sure to add filter_var and mysql_real_escape to your code to secure it up a bit more.
    coming soon sitejuju.com my new development portfolio

  4. #4
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you both for your replys. I appreciate it! Your advice was awesome.

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Also, stop using mysql_ and move to either mysqli_ or a PDO object; the mysql library is discouraged from use.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


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
  •