943,813 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1560
  • PHP RSS
Aug 18th, 2009
0

how to enter data in database from HTML form

Expand Post »
I am trying to use this script to enter data into my database from an html form. this code is not working. plz tell me where the error is
form is

html Syntax (Toggle Plain Text)
  1. <html>
  2.  
  3. <head>
  4. <title> Review, Ratings, Opinions Site </title>
  5. </head>
  6.  
  7. <body text="green" >
  8. <form action="register processing.php" method="post" >
  9. First name: <input type="text" name="fname" value="empty" /> <br/>
  10. Last name: <input type="text" name="lname" value="empty" /> <br/>
  11. Gender:<br/><input type="radio" name="sex" value="male" /> MALE
  12. <input type="radio" name="sex" value="female" /> FEMALE <br/>
  13. Email id: <input type="text" name="email" value="empty" /> <br/>
  14. Username: <input type="text" name="username" value="empty" /> <br/>
  15. password: <input type="password" name="password" value="empty" /> <br/>
  16. <input type="submit" name="submit" value="submit" />
  17. </form>
  18.  
  19. </body>
  20.  
  21. </html>


and the action file is

php Syntax (Toggle Plain Text)
  1. <?php
  2. $handle = mysql_connect("localhost", "root");
  3. if(!$handle)
  4. die("mysql connection failed due to :" . mysql_error());
  5.  
  6.  
  7. $db = mysql_select_db ("review_site" , $handle );
  8. if(!db)
  9. die("database selection failed due to :" . mysql_error());
  10. ?>
  11. <html>
  12. <head>
  13. <title> server side proceesing </title>
  14. </head>
  15.  
  16. <body>
  17. <?php
  18. $fname = $_REQUEST['fname'];
  19. $lname = $_REQUEST['lname'];
  20. $sex = $_REQUEST['sex'];
  21. $email= $_REQUEST['email'];
  22. $username=$_REQUEST['username'];
  23. $password= $_REQUEST['password'];
  24. $v= 1;
  25. $sql = "INSERT INTO users(fname,lname,sex,email,username,password,visible)
  26. VALUES($fname,$lname,$sex,$email,$username,$password,$v)" ;
  27. if($result = mysql_query ($sql, $handle ))
  28. {echo "welcome " . $fname . "<br/>";}
  29. ?>
  30. </body>
  31. </html>
Last edited by Ezzaral; Aug 18th, 2009 at 4:39 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
duraid121 is offline Offline
2 posts
since Aug 2009
Aug 19th, 2009
0

Re: how to enter data in database from HTML form

why r you using php code with in the body tags. are you connected with database?

if yes, then echo your query and paste it in phpmyadmin query area and then check your query is right or wrong.
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009

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: Intergrating javascript with php / mysql
Next Thread in PHP Forum Timeline: update query





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


Follow us on Twitter


© 2011 DaniWeb® LLC