469,330 Members | 1,329 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

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

Hi experts,

I have a form with many textboxes,listboxes 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
Feb 24 '09 #1
8 1939
TheServant
1,168 Expert 1GB
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?
Feb 24 '09 #2
Markus
6,050 Expert 4TB
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.
Feb 24 '09 #3
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
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>post resume</title>
  4. <meta http-equiv=Content-Type" content="text/html">
  5. </head>
  6. <body bgcolor="#CECECE">
  7.  
  8. <h2 style="text-align:center;font-family:courier new;color:#CC3333;font-size:30"><marquee>POST RESUME PAGE</marquee><h2/>
  9. <script type="text/javascript">
  10. function checkform()
  11. {
  12.   var cemail,cmobile,cpercentage,ckeyskills,csalary;
  13.   with(window.document.resumeform)
  14.   {
  15.     cemail=email;
  16.     cmobile=mobile;
  17.     cpercentage=percentage;
  18.     ckeyskills=keyskills;
  19.     csalary=salary;
  20.  
  21.     }
  22.  
  23.     if(trim(cemail.value)=="")
  24.     {
  25.         alert("please enter your email id");
  26.         cemail.focus();
  27.         return false;
  28.     }
  29.     else if(trim(cmobile.value)=="")
  30.     {
  31.         alert("please enter your mobile number");
  32.         cmobile.focus();
  33.         return false;
  34.     }
  35.  
  36.     else if(trim(cpercentage.value)=="")
  37.     {
  38.         alert("please enter your correct percentage");
  39.         cpercentage.focus();
  40.         return false;
  41.     }
  42.  
  43.     else if(trim(ckeyskills.value)=="")
  44.     {
  45.         alert("please enter the keyskills");
  46.         ckeyskills.focus();
  47.         return false;
  48.     }
  49.     else
  50.     {
  51.          cemail.value=trim(cemail.value);
  52.          emobile.value=trim(emobile.value);
  53.          cpercentage.value=trim(cpercentage.value);
  54.          ckeyskills.value=trim(ckeyskills.value);
  55.     }
  56.  
  57.  
  58.  
  59.     function trim(str)
  60.     {
  61.  
  62.         return str.replace(/^\s+|\s+$/g,'');
  63.  
  64.     }
  65.  
  66.  
  67. }
  68.  
  69.  
  70.  
  71. </script>
  72.  
  73. <?php
  74.  
  75. echo "Welcome ";
  76.  
  77. ?>
  78.  
  79. <form action="res.php" onsubmit="return validate_form(this)" method="POST" name="resumeform" >
  80.  
  81.  
  82. <table  cellpadding="80" cellspacing="50" >
  83.  
  84. <tr>
  85. <td ><h2>Contact Info</h2></td>
  86. <td ><h2>Educational Info</h2></td>
  87. </tr>
  88.  
  89. </table>
  90.  
  91. <table  cellspacing="10" cellpadding="8">
  92.  
  93. <td>EMAIL</td>
  94. <td><input type="text" name="email"/>eg.abc@gmail.com<font color="red"> *mandatory</font>
  95.  
  96. </td>
  97.  
  98. <td>HIGHEST QUALIFICATION</td>
  99. <td>
  100. <select name="qualification" id="qualification">
  101. <option value="msc" >M.Sc</option>
  102. <option value="mca">MCA</option>
  103. <option value="be">B.E</option>
  104. <option value="mba">MBA</option>
  105. <option value="mtech">M.Tech</option>
  106. </select>
  107. </td>    
  108. </tr>
  109.  
  110. <tr>
  111. <td>MOBILE</td>
  112. <td><input type="text" name="mobile" /><font color="red">*mandatory</font></td>
  113.  
  114. <td>PERCENTAGE</td>
  115. <td><input type="text" name="percentage"/><font color="red">*mandatory</font></td>
  116.  
  117. </tr>
  118.  
  119.  
  120. <tr>
  121.  
  122. <td>LOCATION</td>
  123. <td>
  124. <select name="location" id="location">
  125. <option value="chennai">Chennai</option>
  126. <option value="mumbai">Mumbai</option>
  127. <option value="delhi">Delhi</option>
  128. <option value="kolkatta">Kolkatta</option>
  129. </select>
  130. </td>    
  131.  
  132. <td>INSTITUTE</td>
  133. <td>
  134. <select name="institute" id="institute">
  135. <option value="anna" >Anna University</option>
  136. <option value="mca">University of Madras</option>
  137. <option value="be">AnnaMalai University</option>
  138. <option value="mba">Kamaraj University</option>
  139. <option value="mtech">Manonmaniam University</option>
  140. </select>
  141. </td>    
  142.  
  143. </tr>
  144.  
  145. <tr>
  146.  
  147. <td>COUNTRY</td>
  148. <td><input type="text" name="country"/></td>
  149.  
  150. <td>OTHERS</td>
  151. <td><input type="text" name="others"/>others specify here</td>
  152.  
  153. </tr>
  154.  
  155. <tr>
  156.  
  157.  
  158. <td>ADDRESS</td>
  159. <td>
  160. <textarea wrap="virtual" name="address" rows="3" cols="15" STYLE="scrollbar-face-color: #317B9C;
  161. scrollbar-track-color: #87B4C9;
  162. scrollbar-arrow-color: #54A1C4;
  163. scrollbar-3dlight-color: #B8D7E6;
  164. scrollbar-shadow-color: #1E6180;
  165. scrollbar-highlight-color: #7CBCDA;
  166. scrollbar-darkshadow-color: #1E6180">
  167. </textarea>
  168. </td>
  169.  
  170. </tr>
  171.  
  172. </table>
  173.  
  174. <table cellpadding="70" cellspacing="50" >
  175.  
  176. <tr>
  177. <td ><h2>Professional Info</h2></td>
  178. <td ><h2>Preferences Info</h2></td>
  179. </tr>
  180.  
  181.  
  182. </table>
  183.  
  184. <table border="0" cellspacing="10" cellpadding="8">
  185.  
  186. <tr>
  187.  
  188. <td>JOB CATEGORY</td>
  189.  
  190. <td>
  191. <select name="jobcategory" id="jobcategory">
  192. <option value="software">Software</option>
  193. <option value="networking">Networking</option>
  194. <option value="finance">Finance</option>
  195. <option value="sales">Sales</option>
  196. </select>
  197.  
  198. </td>
  199.  
  200.  
  201.  
  202. <td>PREFERRED JOB LOCATION</td>
  203.  
  204. <td>
  205. <select name="joblocation" id="joblocation">
  206. <option value="chennai" >Chennai</option>
  207. <option value="delhi">Delhi</option>
  208. <option value="kolkatta">Kolkatta</option>
  209. <option value="mumbai">Mumbai</option>
  210. </select>
  211. </td>    
  212. </tr>
  213.  
  214. <tr>
  215. <td>EXPERIENCE</td>
  216. <td>
  217. <select name="experience" id="experience">
  218. <option value="0" >1</option>
  219. <option value="1" >1</option>
  220. <option value="2">2</option>
  221. <option value="3">3</option>
  222. <option value="4">4</option>
  223. </select>
  224. </td>    
  225.  
  226.  
  227. <td>SALARY EXPECTATION</td>
  228. <td><input type="text" name="salary"/></td>
  229.  
  230. </tr>
  231.  
  232.  
  233. <tr>
  234.  
  235. <td>KEY SKILLS</td>
  236. <td>
  237. <input type="text" name="keyskills"/><font color="red">* mandatory</font>
  238. </td>    
  239.  
  240. <td>RESUME TITLE</td>
  241. <td>
  242. <input type="text" name="resumetitle"/>
  243. </td>    
  244.  
  245. </tr>
  246.  
  247. <tr>
  248.  
  249. <td>EMPLOYER</td>
  250. <td><input type="text" name="employer"/></td>
  251.  
  252. <td><a href="upload.html"><strong>CLICK HERE TO UPLOAD YOUR RESUME</strong></a>
  253. </tr>
  254.  
  255. <!-- <td>UPLOAD RESUME</td>
  256. <td>
  257. <form action="uploadfile.php" method="POST">
  258. <input type="file" name="file" id="file" accept="text/doc"/>
  259. </td>
  260. </form>
  261. </tr>
  262.  
  263. <tr>
  264. <td></td><td></td>
  265. <td>OR COPY RESUME AND PASTE HERE</td>
  266.  
  267. <td>
  268. <textarea rows="5" cols="30" name="copyresume">
  269. </textarea>
  270. </td>
  271.  
  272. </tr>
  273.  -->
  274.  
  275. </table>
  276.  
  277. </br>
  278.  
  279.  <form><center> <input type="submit" name="send" value="POST RESUME" onclick="return checkform()" style="color:#FF6666;background:#FFFFCC" /></center></form>
  280.  <form><center> <input type="submit" value="EDIT RESUME" style="color:#FF6666;background:#FFFFCC" /></center></form>
  281.  
  282.  
  283. </form>
  284. </body>
  285. </head>
  286. </html>
res.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $con=mysql_connect("localhost","root","");
  4. if(!con)
  5. {
  6.     die("cannot connect".mysql_error());
  7. }
  8.  
  9.  
  10.     mysql_select_db("resume_db",$con);
  11.  
  12.  
  13.     mysql_query("insert into res_table
  14.  
  15.     (uname,email,qualification,mobile,percentage,location,institute,country,others,address,jobcategory,joblocation,experience,salary,keyskills,resumetitle,employer) 
  16.  
  17.     values
  18.  
  19.     ('$_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());
  20.  
  21.      $result = mysql_query("SELECT * FROM res_table");
  22.  
  23.  
  24.       echo "<h3>"."You have successfully uploaded your resume"."</h3>."."<br/>";
  25.  
  26.        echo "<h4>"."The contents uploaded in your  resume are as follows"."<h4>";
  27.  
  28.  
  29.  
  30. while($row = mysql_fetch_array($result))
  31.   {
  32.  
  33.       echo "<table align='left' cellspacing='8' cellpadding='20'>";
  34.  
  35.  
  36.  
  37.   echo "<tr>"."<td>"."<b>"."Email:"."&nbsp;"."&nbsp;".$row['email']."</td>"."</tr>";
  38.   echo "<tr>"."<td>"."<b>"."Mobile:"."&nbsp;"."&nbsp;".$row['mobile']."</td>"."</tr>";
  39.   echo "<tr>"."<td>"."<b>"."Location:"."&nbsp;"."&nbsp;".$row['location']."</td>"."</tr>";
  40.   echo "<tr>"."<td>". "<b>"."Country:"."&nbsp;"."&nbsp;".$row['country']."</td>"."</tr>";
  41.   echo "<tr>"."<td>"."<b>"."Address:"."&nbsp;"."&nbsp;".$row['address']."</td>"."</tr>";
  42.   echo "<tr>"."<td>"."<b>"."Qualification:"."&nbsp;"."&nbsp;".$row['qualification']."</td>"."<tr>";
  43.   echo "<tr>"."<td>"."<b>"."Percentage:"."&nbsp;"."&nbsp;".$row['percentage']."</td>"."</tr>";
  44.   echo "<tr>"."<td>"."<b>"."Institute:"."&nbsp;"."&nbsp;".$row['institute']."</td>"."</tr>";
  45.  
  46.  
  47.      echo "</table>";
  48.  
  49.  
  50.     echo "<table align='center' cellspacing='8' cellpadding='20'>";
  51.  
  52.  
  53.  
  54.  echo "<tr>"."<td>"."<b>"."Job Category:"."&nbsp;"."&nbsp;".$row['jobcategory'] ."</td>"."</tr>";
  55.   echo "<tr>"."<td>"."<b>"."Job Location:"."&nbsp;"."&nbsp;".$row['joblocation']."</td>"."</tr>";
  56.   echo "<tr>"."<td>"."<b>"."Experience:"."&nbsp;"."&nbsp;".$row['experience']."</td>"."</tr>";
  57.   echo "<tr>"."<td>"."<b>"."Salary:"."&nbsp;"."&nbsp;".$row['salary']."</td>"."</tr>";
  58.   echo "<tr>"."<td>"."<b>"."KeySkills:"."&nbsp;"."&nbsp;".$row['keyskills']."</td>"."</tr>";
  59.   echo "<tr>"."<td>"."<b>"."Resume Title:"."&nbsp;"."&nbsp;".$row['resumtitle']."</td>"."</tr>";
  60.   echo "<tr>"."<td>"."<b>"."Employer:"."&nbsp;"."&nbsp;".$row['employer']."</td>"."</tr>";
  61.     echo "<tr>"."<td>"."<b>"."Others:"."&nbsp;"."&nbsp;".$row['others']."</td>"."</tr>";
  62.  
  63.  
  64.        echo "</table>";
  65.  
  66.  
  67.  
  68.   }
  69.  
  70.  
  71.  
  72.  ?> 
kindly somebody help me out on this code.urgent.

Thanks
Feb 26 '09 #4
hoopy
88
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:

Expand|Select|Wrap|Line Numbers
  1. mysql_query(".. insert all the data here ..");
  2. $some_id = mysql_insert_id();
  3. $display_q = mysql_query(" select foo from bar where some_id = '$some_id' ");
  4. $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.
Feb 26 '09 #5
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
Feb 26 '09 #6
hoopy
88
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:

Expand|Select|Wrap|Line Numbers
  1. --
  2. -- Database: `job_db`
  3. --
  4.  
  5. CREATE TABLE `resumes` (
  6.   `user_id` int(10) unsigned NOT NULL auto_increment,
  7.   `full_name` varchar(100) NOT NULL,
  8.   `salary` varchar(100) NOT NULL,
  9.   `joined` int(11) NOT NULL,
  10.   PRIMARY KEY  (`user_id`)
  11. ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 ;
Say you had this basic example as your form:

Expand|Select|Wrap|Line Numbers
  1. <form action="display.php" method="post">
  2. Full Name: <input type="text" name="full_name"> <br />
  3. Salary: <input type="text" name="salary"> <br />
  4. <input type="submit" name="submit" value="Insert">
  5. </form>
Then display.php would be like this:

Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. // db connection
  4. mysql_connect("localhost", "root", "")
  5.   or die(mysql_error());
  6. mysql_select_db("job_db")
  7.   or die(mysql_error());
  8.  
  9. // sanitise user input
  10. $full_name = mysql_real_escape_string($_POST['full_name']);
  11. $salary = mysql_real_escape_string($_POST['salary']);
  12. $time = time();
  13.  
  14. // insert the data
  15. mysql_query("
  16.   INSERT INTO resumes 
  17.   (full_name, salary, joined)
  18.   VALUES
  19.   ('$full_name', '$salary', $time)
  20. ") or die(mysql_error());
  21.  
  22. // retrieve the last id inserted 
  23. $user_id = mysql_insert_id();
  24.  
  25. // pull it back out
  26. $query = mysql_query("
  27.   SELECT full_name, salary, joined 
  28.   FROM resumes 
  29.   WHERE user_id = '$user_id' 
  30. ") or die(mysql_error());
  31.  
  32. // store the row
  33. $row = mysql_fetch_array($query);
  34.  
  35. // display the output 
  36. echo ("Name: " . $row['full_name'] . "<br />");
  37. echo ("Salary: " . $row['salary'] . "<br />");
  38. echo ("Joined: " . strftime("%H:%M %d/%m/%y", $row['joined']));
  39.  
  40. ?>
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:

Expand|Select|Wrap|Line Numbers
  1. Name: Hoopy
  2. Salary: 100
  3. 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.
Feb 26 '09 #7
hi hoopy,

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

Thanks
Feb 27 '09 #8
Markus
6,050 Expert 4TB
Please keep off-topic discussion outside of this thread please.

Thank you.

- Markus.
Feb 27 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Nomen Nescio | last post: by
4 posts views Thread by Dan Weeb | last post: by
reply views Thread by Bob Kaku | last post: by
4 posts views Thread by webhigh | last post: by
reply views Thread by Sebi | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.