Php page containing html form to sql database

Reply

Join Date: Nov 2008
Posts: 42
Reputation: squarkman is an unknown quantity at this point 
Solved Threads: 0
squarkman squarkman is offline Offline
Light Poster

Php page containing html form to sql database

 
0
  #1
Dec 15th, 2008
Happy Holidays!

I have a one field form. Upon submission with the submit button, I wish to drive this field value into my SQL database table called MEMBERS and field called NAMES, thus adding a new record.

Can this be done with an OnSubmit() call to a function, in the HEAD of the HTML form page, which contains a series of statements opening the database, entering the data, and closing the database?

  1. <tr>
  2. <td class="mystyle">Your Full Name:</td>
  3. <td><input type="text" name="Name" size="30"></td>
  4. </tr>
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 290
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Php page containing html form to sql database

 
0
  #2
Dec 15th, 2008
Create table in mysql--

create database in mysql with name db_name
  1. CREATE TABLE `table_user` (
  2. `user_id` int(2) NOT NULL auto_increment,
  3. `user_fname` varchar(10) NOT NULL,
  4. `user_lname` varchar(10) NOT NULL,
  5.  
  6. PRIMARY KEY (`user_id`)
  7. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1123 ;

in your php file you have to write like

  1. $con = mysql_connect("localhost","root","");
  2. if (!$con)
  3. {
  4. die('Could not connect: ' . mysql_error());
  5. }
  6. else
  7. {
  8. // echo('Connected with Mysql');
  9. }
  10.  
  11. @mysql_select_db("db_name", $con);// connect to database db_name
  12.  
  13.  
  14. if (isset($_POST['Submit']))
  15. {
  16. $sql="INSERT INTO table_user (user_fname, user_lname) VALUES('$_POST[user_fname]','$_POST[user_lname]')";
  17. @mysql_query($sql,$con);

your form structure like this
  1. <table>
  2. <td width="141" align="left" valign="top" >First Name</td>
  3. <td width="163" align="left" valign="top"><input name="user_fname" type="text" id="user_fname"></td>
  4. <td align="left" valign="top" >Last Name</td>
  5. <td colspan="4" align="left" valign="top"><input name="user_lname" type="text" id="user_lname">
  6.  
  7. <input name="Submit" type="submit" value="Submit" >
  8. </table>
Last edited by Aamit; Dec 15th, 2008 at 8:51 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 42
Reputation: squarkman is an unknown quantity at this point 
Solved Threads: 0
squarkman squarkman is offline Offline
Light Poster

Re: Php page containing html form to sql database

 
0
  #3
Dec 15th, 2008
Thank! Great response. How would you define the 'root' or do I leave the word 'root' as is. Where do I define the url to the server?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 42
Reputation: squarkman is an unknown quantity at this point 
Solved Threads: 0
squarkman squarkman is offline Offline
Light Poster

Re: Php page containing html form to sql database

 
0
  #4
Dec 15th, 2008
Oh, also...where is the connection script placed? Is that PHP or Javascript or HTML? Can I place it anywhere in the code?
Thx
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 290
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Php page containing html form to sql database

 
0
  #5
Dec 15th, 2008
for localhost default user name and password
user name--root
password--"" (blank)

if you want run on server
create user name and password on server & use it
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 290
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Php page containing html form to sql database

 
0
  #6
Dec 15th, 2008
use at top..so make easy for you..
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