Closed Thread
Results 1 to 9 of 9

Thread: Adding a entry

  1. #1
    Davide's Avatar
    Davide is offline Programming God
    Join Date
    Dec 2009
    Location
    Manchester, UK
    Posts
    507
    Blog Entries
    8
    Rep Power
    11

    Adding a entry

    Hello,
    i have a PHP form that is supposed to get a username, password and e-mail. Once the user enters the data, how can i add it to a database?

    Code:
     $name = $_POST['name'];
     $pass = $_POST['password'];
     $email = $_POST['email'];
    Thank you!
    Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    abdul.gafur's Avatar
    abdul.gafur is offline Learning Programmer
    Join Date
    Mar 2010
    Location
    Salo, Riau, Indonesia
    Posts
    42
    Rep Power
    0

    Re: Adding a entry

    • connect to database server
    • select database
    • if you already have database and table, insert it using mysql

    If you find a problem, we will discuss it then

  4. #3
    Davide's Avatar
    Davide is offline Programming God
    Join Date
    Dec 2009
    Location
    Manchester, UK
    Posts
    507
    Blog Entries
    8
    Rep Power
    11

    Re: Adding a entry

    Well it's the code i asked for, cause i know how it is supposed to work.
    Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

  5. #4
    abdul.gafur's Avatar
    abdul.gafur is offline Learning Programmer
    Join Date
    Mar 2010
    Location
    Salo, Riau, Indonesia
    Posts
    42
    Rep Power
    0

    Re: Adding a entry

    What database server that you use?

    Do you already have a database and create table to store the information?

  6. #5
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

    Re: Adding a entry

    Code:
    $username "your_username";
    $password "your_database_password";
    $host "localhost";
    $database "name_of_database_you_using";
    $connection = @mysql_connect($host$username$password) or die("Can not connect to database: ".mysql_error());
    $db = @mysql_select_db($database) or die("Can not select the database: ".mysql_error()); 

  7. #6
    zeroradius's Avatar
    zeroradius is offline Speaks fluent binary
    Join Date
    Feb 2008
    Location
    Ohio
    Posts
    1,403
    Rep Power
    25

    Re: Adding a entry

    Do what Hardinera showed you to connect than to add the data to the tabel

    Note: Replace table with your table name
    Note: the first set were it says (name, pass, email) change to the name of the fileds in your DB.
    Note: Whatever order you put the fileds in is the order you must use for the values

    Code:
     
    $query 
    "Insert into table (name, pass,email) Values ('$_REQUEST[name]', '$_REQUEST[pass]','$_REQUEST[email]')";
    $runQuery mysql_query($query)or die("ERROR:<br /><br />" mysql_error()); 

  8. #7
    Arctic Fire is offline Learning Programmer
    Join Date
    Aug 2009
    Posts
    48
    Rep Power
    0

    Re: Adding a entry

    Before you put those inputted values into that query and run it, you should sanitize them first.

    Code:
    $name mysql_real_escape_string($_POST['name']);
    $pass mysql_real_escape_string($_POST['password']);
    $email mysql_real_escape_string($_POST['email']); 

  9. #8
    Davide's Avatar
    Davide is offline Programming God
    Join Date
    Dec 2009
    Location
    Manchester, UK
    Posts
    507
    Blog Entries
    8
    Rep Power
    11

    Re: Adding a entry

    Thanks guys, i solved it!
    Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

  10. #9
    Jaan Guest

    Re: Adding a entry

    Quote Originally Posted by zeroradius View Post
    Do what Hardinera showed you to connect than to add the data to the tabel

    Note: Replace table with your table name
    Note: the first set were it says (name, pass, email) change to the name of the fileds in your DB.
    Note: Whatever order you put the fileds in is the order you must use for the values

    Code:
     
    $query 
    "Insert into table (name, pass,email) Values ('$_REQUEST[name]', '$_REQUEST[pass]','$_REQUEST[email]')";
    $runQuery mysql_query($query)or die("ERROR:<br /><br />" mysql_error()); 
    Hmm.. You can use this mysql_error() function for yourself but when you are going to upload your program to a web host and publish it make sure to remove it because it will give great info to hackers.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. I need help adding a image
    By CyleDyerHero1 in forum HTML Programming
    Replies: 6
    Last Post: 11-23-2010, 12:09 AM
  2. adding the top score..
    By joie2 in forum C and C++
    Replies: 3
    Last Post: 12-08-2009, 02:50 AM
  3. Adding A Printer
    By WhyLinux in forum Linux Hardware
    Replies: 11
    Last Post: 09-18-2009, 02:09 AM

Tags for this Thread

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