943,568 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 4188
  • PHP RSS
Dec 15th, 2008
0

Php page containing html form to sql database

Expand Post »
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?

PHP Syntax (Toggle Plain Text)
  1. <tr>
  2. <td class="mystyle">Your Full Name:</td>
  3. <td><input type="text" name="Name" size="30"></td>
  4. </tr>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
squarkman is offline Offline
42 posts
since Nov 2008
Dec 15th, 2008
0

Re: Php page containing html form to sql database

Create table in mysql--

create database in mysql with name db_name
PHP Syntax (Toggle Plain Text)
  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

PHP Syntax (Toggle Plain Text)
  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
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008
Dec 15th, 2008
0

Re: Php page containing html form to sql database

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?
Reputation Points: 10
Solved Threads: 0
Light Poster
squarkman is offline Offline
42 posts
since Nov 2008
Dec 15th, 2008
0

Re: Php page containing html form to sql database

Oh, also...where is the connection script placed? Is that PHP or Javascript or HTML? Can I place it anywhere in the code?
Thx
Reputation Points: 10
Solved Threads: 0
Light Poster
squarkman is offline Offline
42 posts
since Nov 2008
Dec 15th, 2008
0

Re: Php page containing html form to sql database

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
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008
Dec 15th, 2008
0

Re: Php page containing html form to sql database

use at top..so make easy for you..
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 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: PHP Date always returns 0
Next Thread in PHP Forum Timeline: Testing





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


Follow us on Twitter


© 2011 DaniWeb® LLC