Error in connecting php mysql and html

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • agarwalsrushti
    New Member
    • Feb 2008
    • 63

    Error in connecting php mysql and html

    Hi,
    Ive created a form in html and written code in hp tht takes data feom html and stores it in MySQL database. Bt wen i click on the submit button i get an error. Instead of storing it in database it asks to open the php file which has bees specified in the action attribute of the form tag. It is being created for windows platform.
    Im pasting the code of both the html and php file that ive used and plz let me know how to fix that problem.
    File name:form.html
    [code=html]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <HTML xmlns="http://www.w3.org/1999/xhtml">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <HEAD>
    <TITLE>Form Handling with PHP</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFF F">
    <FORM METHOD=POST ACTION="add.php ">
    <input type="hidden" name="id" value="NULL">
    <TABLE>
    <TR height="20">
    <TD colspan="2"><FO NT SIZE="+0" face="verdana"> Below is a Sample Form for our PHP tutorial</TD>
    </TR>
    <TR height="50">
    <td></td>
    </TR>
    <TR>
    <TD align="left"><F ONT SIZE="+0" face="verdana"> <b>Your Name <br>
    Your E-Mail Address</b></td>
    <td><INPUT TYPE="text" NAME="name">
    <br>
    <INPUT TYPE="text" NAME="email">
    </TD>
    </TR>
    <tr>
    <td colspan="2"><ce nter>
    <SELECT NAME="opinion">
    <option value="is great">I like your site</option>
    <option value="is OK">Your Site is OK</option>
    <option value="is horrible">Your Site is horrible</option>
    </SELECT>
    <INPUT TYPE="submit" value="Tell us!">
    </td>
    </tr>
    </TABLE>
    </FORM>
    </BODY>
    </HTML>
    [/code]
    Filename:add.ph p
    [code=php]
    <?
    $DBhost = "localhost" ;
    $DBuser = "root";
    $DBpass = "database";
    $DBName = "test";
    $table = "informatio n";
    mysql_connect($ DBhost,$DBuser, $DBpass) or die("Unable to connect to database");

    @mysql_select_d b("$DBName") or die("Unable to select
    database $DBName");

    $sqlquery = "INSERT INTO $table
    VALUES('$id','$ name','$email', '$opinion')";

    $results = mysql_query($sq lquery);

    mysql_close();

    print "<HTML><TIT LE> PHP and MySQL </TITLE><BODY
    BGCOLOR=\"#FFFF FF\"><center><t able border=\"0\"
    width=\"500\">< tr><td>";
    print "<p><font face=\"verdana\ " size=\"+0\"> <center>You
    Just Entered This Information Into the
    Database<p><blo ckquote>";
    print "Name : $name<p>E-Mail : $email<p>Opinio n :
    $opinion</blockquote></td></tr></table>
    </center></BODY></HTML>";
    ?>
    [/code]

    Plz help me out as soon as possible.
    Thanks
    Last edited by ak1dnar; Feb 14 '08, 03:31 AM. Reason: CODE Tags missing
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    Are you executing these pages with a web server, then what is it?
    Is php is configured to work with the web server?

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      This is Not a Good thread title;
      Error in connecting php mysql and html (Plz help urgently)
      But this is
      Error in connecting php mysql and html

      So avoid using these words *please* *help* *urgent*
      and make sure to use the CODE tags. refer to Posting guidelines first
      Thanks

      Comment

      • agarwalsrushti
        New Member
        • Feb 2008
        • 63

        #4
        Originally posted by ak1dnar
        Are you executing these pages with a web server, then what is it?
        Is php is configured to work with the web server?

        Im using xampp to run this web pages.php is configured in it. Ive created the database in MySQL using xampp. Plz let me know
        Thanks

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by agarwalsrushti
          Im using xampp to run this web pages.php is configured in it. Ive created the database in MySQL using xampp. Plz let me know
          Thanks
          Is xampp running (check apache)?
          Ar you saving the files in the righte directory (htdocs)?

          Comment

          • agarwalsrushti
            New Member
            • Feb 2008
            • 63

            #6
            Hey thanks my that problem has got solved. I saved in wrong folder. Can u plz tel me like when user fills form i had asked him to retype pssword to confirm. What is the way that we verify it. Plz let me know how to do this. Is there a function available or v hve to apply some logic

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Originally posted by agarwalsrushti
              Hey thanks my that problem has got solved. I saved in wrong folder. Can u plz tel me like when user fills form i had asked him to retype pssword to confirm. What is the way that we verify it. Plz let me know how to do this. Is there a function available or v hve to apply some logic
              Well, you can either use javascript or php?
              Javascript is client side, and therefore we can alert the user before the form is submitted.
              ORRRRRRRRRRRRRR R!
              Php, server side, this could be used in add.php and then notify the user that the passwords didnt match and provide a back button for him to return and try again!
              Here's an example for javascript:
              [code=javascript]
              function validatePasswor d()
              {
              var passWord = document.form_n ame.input_name. value;
              var passWordS = document.form_n ame.input_name. value;
              if(passWord == passWordS)
              {
              // the passwords matched ... submit form
              document.form_n ame.submit();
              }
              else
              {
              // the passwords DIDNT match ... alert user
              alert("Sorry, there was an error:\n\nPassw ords didn't match");
              document.form_n ame.input_name. focus();
              return false;
              }
              }
              [/code]
              Obviously, you'd have to adapt it to your form and use the correct form_name's and input_name's

              And a php method:
              [php]
              $_passwordA = $_POST['passwordA'];
              $_passwordB = $_POST['passwordB'];

              if($_passwordA == $_passwordB)
              {
              // passwords matched
              // execute the code.
              }
              else
              {
              // passes didnt match:
              echo "The passwords you provided didn't match<br />";
              echo "Please use <a href=\"javascri pt: history.back(); \">this link</a> to return to the form!";
              }
              [/php]

              Hope this helps you :)

              Comment

              • agarwalsrushti
                New Member
                • Feb 2008
                • 63

                #8
                hi,
                I tried using your php code but it didnt worked out. Ive attached my php file below without the pasword code.
                Plz try n tel me if it works.
                html filename is register.html and php filename is process.php
                Plz let me know.
                PHP file
                [code=php]
                <?php

                # THIS CODE DEFINES THE DATABASE TO BE FILLED
                $hostname = "localhost" ;
                $db_user = "root";
                $db_password = "database";
                $db_name = "skills_portfol io";
                $db_table1 = "functionalarea ";
                $db_table2 = "functionalrole ";
                $db_table3 = "institute" ;
                $db_table4 = "qualification" ;
                $db_table5 = "specialization ";
                $db_table6 = "tagmaster" ;
                $db_table7 = "userdetail s";
                $db_table8 = "usermaster ";
                $db_table9 = "usertags";

                # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE
                $dbi=mysql_conn ect($hostname, $db_user, $db_password);
                mysql_select_db ($db_name,$dbi) ;

                if (isset($_REQUES T['Submit']))
                {
                # THIS CODE INSERTS THE DATA FROM THE FORM INTO MYSQL TABLE

                mysql_query( "INSERT INTO $db_table1(Area Name)values('$_ POST[AreaName]')")
                or die(mysql_error ());

                mysql_query("IN SERT INTO $db_table2(Role Name) values('$_POST[RoleName]')")
                or die(mysql_error ());

                mysql_query("IN SERT INTO $db_table3(Inst ituteName)
                values('$_POST[InstituteName]')")
                or die(mysql_error ());

                mysql_query("IN SERT INTO $db_table4(Qual ificationName) values ('$_POST[QualificationNa me]')")
                or die(mysql_error ());

                mysql_query("IN SERT INTO $db_table5(Spec ializationArea) values ('$_POST[SpecializationA rea]')")
                or die(mysql_error ());

                mysql_query("IN SERT INTO $db_table7(User Name,PhoneNo,Mo bileNo,YearsExp ,
                MonthsExp,Funct ionalArea,KeySk ills,Qualificat ion,Specializat ion,Institute,
                FunctionalRoles ,CurrentEmploye r,PreviousEmplo yers,ProfileTit le,ResumeFile)
                values ('$_POST[UserName]','$_POST[PhoneNo]','$_POST[MobileNo]',
                '$_POST[YearsExp]','$_POST[MonthsExp]','$_POST[AreaName]',
                '$_POST[KeySkills]','$_POST[QualificationNa me]','$_POST[SpecializationA rea]',
                '$_POST[Institute]','$_POST[RoleName]','$_POST[CurrentEmployer]',
                '$_POST[PreviousEmploye rs]','$_POST[ProfileTitle]','$_POST[ResumeFile]')")
                or die(mysql_error ());

                mysql_query("IN SERT INTO $db_table8(User Name,UserPasswo rd,FullName,Ema ilAddress)
                values ('$_POST[UserName]','$_POST[UserPassword]','$_POST[FullName]',
                '$_POST[EmailAddress]')") or die(mysql_error ()) ;

                mysql_query( "INSERT INTO $db_table9(User Name)values('$_ POST[UserName]')")
                or die(mysql_error ());

                echo "Congrats, Your have been successfully registered on our portal";

                }

                ?>
                [/code]

                Comment

                • agarwalsrushti
                  New Member
                  • Feb 2008
                  • 63

                  #9
                  hi,
                  plz can anyone help me out

                  Comment

                  • upsingh1975
                    New Member
                    • Feb 2008
                    • 1

                    #10
                    you use software called EasyPhp which enables the php pages to be displayed on the windows environment.

                    it also runs Apache and Mysql Server.

                    copy all your pages in the Program Files -> EasyPhp -> www folder and run the IE as http://localhost/yourfile.php

                    you problem will be solved.

                    Comment

                    • agarwalsrushti
                      New Member
                      • Feb 2008
                      • 63

                      #11
                      Hi,
                      Thanx but i can view my pages thats not a problem.
                      I ve written the pages in html but i want to verify that the user during registration types the pasword and retype pasword same or not. i want the logic for this part.

                      Comment

                      • Markus
                        Recognized Expert Expert
                        • Jun 2007
                        • 6092

                        #12
                        Originally posted by agarwalsrushti
                        Hi,
                        Thanx but i can view my pages thats not a problem.
                        I ve written the pages in html but i want to verify that the user during registration types the pasword and retype pasword same or not. i want the logic for this part.
                        i gave you the logic...

                        [php]
                        if(password_a == password_b)
                        {
                        // run the mysql queries
                        }
                        else
                        {
                        // the passwords didnt match
                        }
                        [/php]

                        Comment

                        • agarwalsrushti
                          New Member
                          • Feb 2008
                          • 63

                          #13
                          Thanks alot. That logic worked but have a small problem in it. If the password doesnt match it than also stores the other info in all other tables. Also how should i send the user back to fill in the password. should i specify the html file path for it in href. I also wanted to know about making a compulsion for password strength.
                          Thanks again

                          Comment

                          • agarwalsrushti
                            New Member
                            • Feb 2008
                            • 63

                            #14
                            Hi,
                            It is working now my that peoblem also got solved. I want that if the paswords dont match than when the user returns the registration page then he should not be asked to type all the information again. It should appear on screen and should only be asked to enter the paswords again. My other problem of pasword strength is not solved yet. Plz let me know.

                            Comment

                            • agarwalsrushti
                              New Member
                              • Feb 2008
                              • 63

                              #15
                              Plz can anyone tel me how ro set minimum number of characters for pasword criteria in a form.

                              Comment

                              Working...