DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   Php page containing html form to sql database (http://www.daniweb.com/forums/thread162348.html)

squarkman Dec 15th, 2008 8:24 am
Php page containing html form to sql database
 
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?

<tr>
        <td class="mystyle">Your Full Name:</td>
        <td><input type="text" name="Name" size="30"></td>
</tr>

Aamit Dec 15th, 2008 8:46 am
Re: Php page containing html form to sql database
 
Create table in mysql--

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

in your php file you have to write like

$con = mysql_connect("localhost","root","");
        if (!$con)
          {
          die('Could not connect: ' . mysql_error());
          }
          else
          {
        // echo('Connected with Mysql');
          }

@mysql_select_db("db_name", $con);// connect to database db_name


        if (isset($_POST['Submit']))
        {
$sql="INSERT INTO table_user (user_fname, user_lname)        VALUES('$_POST[user_fname]','$_POST[user_lname]')";
                @mysql_query($sql,$con);

your form structure like this
<table>
 <td width="141" align="left" valign="top" >First Name</td>
                          <td width="163" align="left" valign="top"><input name="user_fname" type="text" id="user_fname"></td>
<td align="left" valign="top" >Last Name</td>
                          <td colspan="4" align="left" valign="top"><input name="user_lname" type="text" id="user_lname">

<input name="Submit" type="submit" value="Submit" >
</table>

squarkman Dec 15th, 2008 8:51 am
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?

squarkman Dec 15th, 2008 8:54 am
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

Aamit Dec 15th, 2008 8:55 am
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

Aamit Dec 15th, 2008 8:57 am
Re: Php page containing html form to sql database
 
use at top..so make easy for you..


All times are GMT -4. The time now is 6:51 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC