www.webdeveloper.com
Results 1 to 3 of 3

Thread: Connect PHP Dreamweaver form to Database

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    2

    Smile Connect PHP Dreamweaver form to Database

    I'm developing a web based information system in PHP. I'm using WAMP server2 and Dreamweaver CS3 for that. I have developed many forms in Dreamweaver and my database is created in WAMP server. I want to connect those forms to the database. I selected Windows > Database from the menu in the Dreamweaver but in the small window that i got on the left hand side in Dreamweaver window the + mark is disabled. If so please tell me how can I connect my form to MySQL database.
    Waiting for your kind support.
    Many Thanks.

  2. #2
    Join Date
    Sep 2008
    Location
    Southern California
    Posts
    79

    Code

    Put some code on here or link to see if I can help

  3. #3
    Join Date
    Jul 2009
    Posts
    2

    Smile Thank you so much for your reply.Here is the code of relavant 3 files.

    Thank you very much for your reply. That’s kind of you.

    The “emp.htm” is the code for a HTML form I want to save the incoming data entered through this form to the following MYSQL database table.
    Database: hrms
    Table: employee
    Fields: empNo, Name, Address, Salary

    I’m using Dreamweaver for coding and WAMP server for the other relevant works. I created a mySQL connection to the database (hrms). Then a folder called “connections” automatically created inside the folder (folder name is exercise) that I save my php and html files. In the connections folder there is a file called “conn.php”.

    I have already created the database ‘hrms’ and the table ‘employee’ in phpmyAdmin.

    My problem is even I have done everything correctly, once I enter the values to the fields of the Form and click Save button, it doesn’t save data to the table and getting the message “Error Occurred”

    It’s great If you could help me to fix this problem.


    “conn.php”:-

    <?php
    # FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_conn = "localhost";
    $database_conn = "hrms";
    $username_conn = "root";
    $password_conn = "";
    $conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR);
    ?>

    “emp.htm”:-

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <form action="testing.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
    Employee No:
    <input type="text" name="txtEmpNo" id="txtEmpNo" />
    Name:
    <input type="text" name="txtName" id="txtName" />
    Address:
    <input type="text" name="txtAddress" id="txtAddress" />
    Salary:
    <input type="text" name="txtSalary" id="txtSalary" />
    <br /><br />
    <input type="submit" name="save" id="save" value="Save" />
    <input type="reset" name="clear" id="clear" value="Clear" />
    <input type="submit" name="exit" id="exit" value="Exit" />
    <br />
    </form>
    </body>
    </html>

    “testing.php”:-

    <html>
    <head>
    </head>
    <body>
    <?php
    $data=array($_POST['txtEmpNo'],$_POST['txtName'],$_POST['txtAddress'],$_POST['txtSalary']);
    $server = "localhost";
    $username = "root";
    $password = "";
    $conn = mysql_connect($server, $username, $password) or die("DB connection failed");
    mysql_select_db("hrms",$conn) or die("unable to open DB");
    $query="INSERT into 'employee' values($data[0],$data[1],$data[2],$data[3])";
    if(mysql_query($query,$conn)){
    print"Record added successfully"; }
    else{
    print"Error occured"; }
    mysql_close($conn);
    ?>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles