editing the values in the form and submit to the mysql database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ahilar12
    New Member
    • Feb 2009
    • 27

    editing the values in the form and submit to the mysql database

    Hi experts,

    I have a form with many textboxes,listb oxes in php.I have a edit button to edit the values in the form.once i click the edit button the existing values should be displayed so that the user can edit those particular values and also that should be updated in the mysql database.kindly reply me as early as possible.

    Thanks
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    So when the user clicks edit do you want the page to reload or to just display/enable the text boxes? If you reload you need to send the form to itself (via the action attribute) and check if the method of the page load is "post" and if so, you can have different options with the form via using PHP.
    If you don't want the page to load, you need to use javascript to change the form inputs properties and show the "submit" button.

    I am not going to write the code for you as the purpose of these forums is not to work for nothing, but help those with some code they already have. Try and get this script working and if you get stuck come back and we'll be happy to help.

    PS - How much do you know about PHP and/or MySQL?

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      I don't see a question in that post. Please revise your post to include a question and sufficient details of your problem. Also, you should post the code you have attempted to solved your problem with - we do not hand out code.

      Moderator.

      Comment

      • ahilar12
        New Member
        • Feb 2009
        • 27

        #4
        urgently required source code for editing the values in the form and to store

        hi experts,
        I have attached the code for the form and the database connection.
        I want the code to edit the existing values in the form and to store the edited values in the database.

        res.html
        [code=php]
        <html>
        <head>
        <title>post resume</title>
        <meta http-equiv=Content-Type" content="text/html">
        </head>
        <body bgcolor="#CECEC E">

        <h2 style="text-align:center;fo nt-family:courier new;color:#CC33 33;font-size:30"><marqu ee>POST RESUME PAGE</marquee><h2/>
        <script type="text/javascript">
        function checkform()
        {
        var cemail,cmobile, cpercentage,cke yskills,csalary ;
        with(window.doc ument.resumefor m)
        {
        cemail=email;
        cmobile=mobile;
        cpercentage=per centage;
        ckeyskills=keys kills;
        csalary=salary;

        }

        if(trim(cemail. value)=="")
        {
        alert("please enter your email id");
        cemail.focus();
        return false;
        }
        else if(trim(cmobile .value)=="")
        {
        alert("please enter your mobile number");
        cmobile.focus() ;
        return false;
        }

        else if(trim(cpercen tage.value)=="" )
        {
        alert("please enter your correct percentage");
        cpercentage.foc us();
        return false;
        }

        else if(trim(ckeyski lls.value)=="")
        {
        alert("please enter the keyskills");
        ckeyskills.focu s();
        return false;
        }
        else
        {
        cemail.value=tr im(cemail.value );
        emobile.value=t rim(emobile.val ue);
        cpercentage.val ue=trim(cpercen tage.value);
        ckeyskills.valu e=trim(ckeyskil ls.value);
        }



        function trim(str)
        {

        return str.replace(/^\s+|\s+$/g,'');

        }


        }



        </script>

        <?php

        echo "Welcome ";

        ?>

        <form action="res.php " onsubmit="retur n validate_form(t his)" method="POST" name="resumefor m" >


        <table cellpadding="80 " cellspacing="50 " >

        <tr>
        <td ><h2>Contact Info</h2></td>
        <td ><h2>Educationa l Info</h2></td>
        </tr>

        </table>

        <table cellspacing="10 " cellpadding="8" >

        <td>EMAIL</td>
        <td><input type="text" name="email"/>eg.abc@gmail.c om<font color="red"> *mandatory</font>

        </td>

        <td>HIGHEST QUALIFICATION</td>
        <td>
        <select name="qualifica tion" id="qualificati on">
        <option value="msc" >M.Sc</option>
        <option value="mca">MCA </option>
        <option value="be">B.E</option>
        <option value="mba">MBA </option>
        <option value="mtech">M .Tech</option>
        </select>
        </td>
        </tr>

        <tr>
        <td>MOBILE</td>
        <td><input type="text" name="mobile" /><font color="red">*ma ndatory</font></td>

        <td>PERCENTAG E</td>
        <td><input type="text" name="percentag e"/><font color="red">*ma ndatory</font></td>

        </tr>


        <tr>

        <td>LOCATION</td>
        <td>
        <select name="location" id="location">
        <option value="chennai" >Chennai</option>
        <option value="mumbai"> Mumbai</option>
        <option value="delhi">D elhi</option>
        <option value="kolkatta ">Kolkatta</option>
        </select>
        </td>

        <td>INSTITUTE </td>
        <td>
        <select name="institute " id="institute" >
        <option value="anna" >Anna University</option>
        <option value="mca">Uni versity of Madras</option>
        <option value="be">Anna Malai University</option>
        <option value="mba">Kam araj University</option>
        <option value="mtech">M anonmaniam University</option>
        </select>
        </td>

        </tr>

        <tr>

        <td>COUNTRY</td>
        <td><input type="text" name="country"/></td>

        <td>OTHERS</td>
        <td><input type="text" name="others"/>others specify here</td>

        </tr>

        <tr>


        <td>ADDRESS</td>
        <td>
        <textarea wrap="virtual" name="address" rows="3" cols="15" STYLE="scrollba r-face-color: #317B9C;
        scrollbar-track-color: #87B4C9;
        scrollbar-arrow-color: #54A1C4;
        scrollbar-3dlight-color: #B8D7E6;
        scrollbar-shadow-color: #1E6180;
        scrollbar-highlight-color: #7CBCDA;
        scrollbar-darkshadow-color: #1E6180">
        </textarea>
        </td>

        </tr>

        </table>

        <table cellpadding="70 " cellspacing="50 " >

        <tr>
        <td ><h2>Profession al Info</h2></td>
        <td ><h2>Preference s Info</h2></td>
        </tr>


        </table>

        <table border="0" cellspacing="10 " cellpadding="8" >

        <tr>

        <td>JOB CATEGORY</td>

        <td>
        <select name="jobcatego ry" id="jobcategory ">
        <option value="software ">Software</option>
        <option value="networki ng">Networkin g</option>
        <option value="finance" >Finance</option>
        <option value="sales">S ales</option>
        </select>

        </td>



        <td>PREFERRED JOB LOCATION</td>

        <td>
        <select name="joblocati on" id="joblocation ">
        <option value="chennai" >Chennai</option>
        <option value="delhi">D elhi</option>
        <option value="kolkatta ">Kolkatta</option>
        <option value="mumbai"> Mumbai</option>
        </select>
        </td>
        </tr>

        <tr>
        <td>EXPERIENC E</td>
        <td>
        <select name="experienc e" id="experience" >
        <option value="0" >1</option>
        <option value="1" >1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        </select>
        </td>


        <td>SALARY EXPECTATION</td>
        <td><input type="text" name="salary"/></td>

        </tr>


        <tr>

        <td>KEY SKILLS</td>
        <td>
        <input type="text" name="keyskills "/><font color="red">* mandatory</font>
        </td>

        <td>RESUME TITLE</td>
        <td>
        <input type="text" name="resumetit le"/>
        </td>

        </tr>

        <tr>

        <td>EMPLOYER</td>
        <td><input type="text" name="employer"/></td>

        <td><a href="upload.ht ml"><strong>CLI CK HERE TO UPLOAD YOUR RESUME</strong></a>
        </tr>

        <!-- <td>UPLOAD RESUME</td>
        <td>
        <form action="uploadf ile.php" method="POST">
        <input type="file" name="file" id="file" accept="text/doc"/>
        </td>
        </form>
        </tr>

        <tr>
        <td></td><td></td>
        <td>OR COPY RESUME AND PASTE HERE</td>

        <td>
        <textarea rows="5" cols="30" name="copyresum e">
        </textarea>
        </td>

        </tr>
        -->

        </table>

        </br>

        <form><center > <input type="submit" name="send" value="POST RESUME" onclick="return checkform()" style="color:#F F6666;backgroun d:#FFFFCC" /></center></form>
        <form><center > <input type="submit" value="EDIT RESUME" style="color:#F F6666;backgroun d:#FFFFCC" /></center></form>


        </form>
        </body>
        </head>
        </html>[/code]

        res.php
        [code=php]
        <?php

        $con=mysql_conn ect("localhost" ,"root","");
        if(!con)
        {
        die("cannot connect".mysql_ error());
        }


        mysql_select_db ("resume_db",$c on);


        mysql_query("in sert into res_table

        (uname,email,qu alification,mob ile,percentage, location,instit ute,country,oth ers,address,job category,jobloc ation,experienc e,salary,keyski lls,resumetitle ,employer)

        values

        ('$_POST[uname]','$_POST[email]','$_POST[qualification]','$_POST[mobile]','$_POST[percentage]','$_POST[location]','$_POST[institute]','$_POST[country]','$_POST[others]','$_POST[address]','$_POST[jobcategory]','$_POST[joblocation]','$_POST[experience]','$_POST[salary]','$_POST[keyskills]','$_POST[resumetitle]','$_POST[employer]')") or die(mysql_error ());

        $result = mysql_query("SE LECT * FROM res_table");


        echo "<h3>"."You have successfully uploaded your resume"."</h3>."."<br/>";

        echo "<h4>"."The contents uploaded in your resume are as follows"."<h4>" ;



        while($row = mysql_fetch_arr ay($result))
        {

        echo "<table align='left' cellspacing='8' cellpadding='20 '>";



        echo "<tr>"."<td>"." <b>"."Email:"." &nbsp;"."&nbsp; ".$row['email']."</td>"."</tr>";
        echo "<tr>"."<td>"." <b>"."Mobile:". "&nbsp;"."&nbsp ;".$row['mobile']."</td>"."</tr>";
        echo "<tr>"."<td>"." <b>"."Location: "."&nbsp;"."&nb sp;".$row['location']."</td>"."</tr>";
        echo "<tr>"."<td >". "<b>"."Country: "."&nbsp;"."&nb sp;".$row['country']."</td>"."</tr>";
        echo "<tr>"."<td>"." <b>"."Address:" ."&nbsp;"."&nbs p;".$row['address']."</td>"."</tr>";
        echo "<tr>"."<td>"." <b>"."Qualifica tion:"."&nbsp;" ."&nbsp;".$r ow['qualification']."</td>"."<tr>";
        echo "<tr>"."<td>"." <b>"."Percentag e:"."&nbsp;"."& nbsp;".$row['percentage']."</td>"."</tr>";
        echo "<tr>"."<td>"." <b>"."Institute :"."&nbsp;"."&n bsp;".$row['institute']."</td>"."</tr>";


        echo "</table>";


        echo "<table align='center' cellspacing='8' cellpadding='20 '>";



        echo "<tr>"."<td>"." <b>"."Job Category:"."&nb sp;"."&nbsp;".$ row['jobcategory'] ."</td>"."</tr>";
        echo "<tr>"."<td>"." <b>"."Job Location:"."&nb sp;"."&nbsp;".$ row['joblocation']."</td>"."</tr>";
        echo "<tr>"."<td>"." <b>"."Experienc e:"."&nbsp;"."& nbsp;".$row['experience']."</td>"."</tr>";
        echo "<tr>"."<td>"." <b>"."Salary:". "&nbsp;"."&nbsp ;".$row['salary']."</td>"."</tr>";
        echo "<tr>"."<td>"." <b>"."KeySkills :"."&nbsp;"."&n bsp;".$row['keyskills']."</td>"."</tr>";
        echo "<tr>"."<td>"." <b>"."Resume Title:"."&nbsp; "."&nbsp;". $row['resumtitle']."</td>"."</tr>";
        echo "<tr>"."<td>"." <b>"."Employer: "."&nbsp;"."&nb sp;".$row['employer']."</td>"."</tr>";
        echo "<tr>"."<td>"." <b>"."Others:". "&nbsp;"."&nbsp ;".$row['others']."</td>"."</tr>";


        echo "</table>";



        }



        ?> [/code]

        kindly somebody help me out on this code.urgent.

        Thanks
        Last edited by Atli; Feb 26 '09, 11:05 AM. Reason: Moved this post here from it's own thread, and added [code] tags.

        Comment

        • hoopy
          New Member
          • Feb 2009
          • 88

          #5
          The code display on this site is not wide enough in my opinion.

          What exactly are you trying to achieve? I assume its an basic insert of a record, then pulling it out again and displaying it?

          When you insert the data you could then get the last ID entered with mysql_insert_id () then you can pull it out again I guess something like:

          Code:
          mysql_query(".. insert all the data here ..");
          $some_id = mysql_insert_id();
          $display_q = mysql_query(" select foo from bar where some_id = '$some_id' ");
          $row = mysql_fetch_array($display_q);
          Then display the data as need be. It seems like you are trying to pull everything again and display it.

          Can you advise what the actual problem is.

          Thanks.

          Comment

          • ahilar12
            New Member
            • Feb 2009
            • 27

            #6
            Required a solution urgently hoopy

            Thanks for u r reply hoopy,
            I m a beginner to php.so the code will not be that much wide enough.any way i m developing a small demo application like a jobsite for my project.
            created a login page,profile page and the post resume page to input the details of the candidates.here i have 2 buttons one to post resume and the other is to edit resume .
            if we click the edit resume button the existing values of the user should be populated in the inputboxes and listboxes and the user is allowed to edit those values and once the edit resume button is clicked the values gets updated in the database and displayed again.
            Able to catch atleast to some extent.pls try to help me out on this.need a sample code for this.

            Thanks

            Comment

            • hoopy
              New Member
              • Feb 2009
              • 88

              #7
              I dont know how you have your DB setup and I have dont have a lot of time right now but if you can follow this then you can see quite simply how it works. Say your DB Is laid out like this:

              Code:
              --
              -- Database: `job_db`
              --
              
              CREATE TABLE `resumes` (
                `user_id` int(10) unsigned NOT NULL auto_increment,
                `full_name` varchar(100) NOT NULL,
                `salary` varchar(100) NOT NULL,
                `joined` int(11) NOT NULL,
                PRIMARY KEY  (`user_id`)
              ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 ;
              Say you had this basic example as your form:

              Code:
              <form action="display.php" method="post">
              Full Name: <input type="text" name="full_name"> <br />
              Salary: <input type="text" name="salary"> <br />
              <input type="submit" name="submit" value="Insert">
              </form>
              Then display.php would be like this:

              Code:
              <?
              
              // db connection
              mysql_connect("localhost", "root", "")
                or die(mysql_error());
              mysql_select_db("job_db")
                or die(mysql_error());
                
              // sanitise user input
              $full_name = mysql_real_escape_string($_POST['full_name']);
              $salary = mysql_real_escape_string($_POST['salary']);
              $time = time();
              
              // insert the data
              mysql_query("
                INSERT INTO resumes 
                (full_name, salary, joined)
                VALUES
                ('$full_name', '$salary', $time)
              ") or die(mysql_error());
              
              // retrieve the last id inserted 
              $user_id = mysql_insert_id();
              
              // pull it back out
              $query = mysql_query("
                SELECT full_name, salary, joined 
                FROM resumes 
                WHERE user_id = '$user_id' 
              ") or die(mysql_error());
              
              // store the row
              $row = mysql_fetch_array($query);
              
              // display the output 
              echo ("Name: " . $row['full_name'] . "<br />");
              echo ("Salary: " . $row['salary'] . "<br />");
              echo ("Joined: " . strftime("%H:%M %d/%m/%y", $row['joined']));
              
              ?>
              I have tried to keep it as simple as possible. So if you went to that form, and entered those variables it would sanitise the input. Input the data into the table then retrieve the ID which was just inserted, pull it out again and display it.

              So it may look something like:

              Code:
              Name: Hoopy
              Salary: 100
              Joined: 17:40 26/02/09
              If you follow this principle with your code then you should be OK. mysql_insert_id is what you need to look into and the ID it will return is determined by how your database table is setup.

              Also the comment about the width was not about your code, it was about the width which Bytes makes the code display, its always a bit too narrow imo.

              Hope this help. Good Luck.

              Comment

              • ahilar12
                New Member
                • Feb 2009
                • 27

                #8
                hi hoopy,

                Good After noon,
                thanks for u r code.i will check out and revert back to u.

                Thanks

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Please keep off-topic discussion outside of this thread please.

                  Thank you.

                  - Markus.

                  Comment

                  Working...