how to enter data in database from HTML form

Reply

Join Date: Aug 2009
Posts: 2
Reputation: duraid121 is an unknown quantity at this point 
Solved Threads: 0
duraid121 duraid121 is offline Offline
Newbie Poster

how to enter data in database from HTML form

 
0
  #1
Aug 18th, 2009
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

  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

  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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 254
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: how to enter data in database from HTML form

 
0
  #2
Aug 19th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC