943,186 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 603
  • PHP RSS
Jul 6th, 2010
-1

help in php database connection

Expand Post »
hello guys , please tell me how to connect my php form to a database and save data and also getting data from my database
i hope you give me the code
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Member 784361 is offline Offline
6 posts
since Jul 2010
Jul 6th, 2010
0
Re: help in php database connection
I am not 100% sure what you mean, but I'll try to help you. First, I hope that you got MySQL installed. Let's assume that you got a database called "mysite" with a table called "users" that contains two rows called "username" and "password". Both username and password is root.

index.php (The form)
PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <body>
  3. <form method="post" action="submit.php">
  4. Username:<input type="text" name="username"></input><br>
  5. Password:<input type="password" name="password"></input>
  6. </form>
  7. </body>
  8. </html>
submit.php (The MySQL part)
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. mysql_connect("localhost","root","root"); //mysql_connect(host,username,password)
  3. mysql_select_db("mysite"); //Select the database mysite.
  4. $username=mysql_real_escape_string($_POST[username]); //mysql_real_escape_string protects you from sql injections that could "hack" your database.
  5. $password=mysql_real_escape_string($_POST[password]); //if you name a input field password, it is avalible in the $_POST[password] variable
  6. mysql_query("INSERT INTO users (username,password) VALUES('$username','$password')"); //The query that inserts everything to the database.
  7. ?>
  8. OK!

I didn't test this code, please reply if you receive any errors(or even better, solve them!).

Hope it helps, and good luck!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Member 785088 is offline Offline
2 posts
since Jul 2010
Jul 6th, 2010
0
Re: help in php database connection
thank you for giving me the code but i am new at php and all what i did on my hosting is that i created mysql database with the name but i did not define the name of any table so what do i need to do more
sorry for disturbing but as you know i am new at php and i dont know many things at it
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Member 784361 is offline Offline
6 posts
since Jul 2010
Jul 7th, 2010
0
Re: help in php database connection
http://www.webdevelopersnotes.com/tu...ng_tables.php3

Before getting into the subject please go thru some tutorials for php and mysql
Reputation Points: 167
Solved Threads: 239
Nearly a Posting Virtuoso
rajarajan07 is offline Offline
1,445 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: [split] project help
Next Thread in PHP Forum Timeline: doubt in contact form mail sending coding in php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC