473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Text link does accidental dbl insert

daJunkCollector
Hey, I have a simple web app that requires the user to click a text link to add a section to the form. As you will see from the following code (PHP/mySQL), the link inserts a row into the database table. The problem is that, during testing, sometimes when I click the link, two rows are added instead of only one. I only want one row to be added. Could you please help me figure out my bug?

Expand|Select|Wrap|Line Numbers
  1. // Insert and delete actions for Education, Work Experiences, and References
  2.         if($_GET['action']=="insertEdu" && $_GET['checkId'] == $_SESSION['usrId'] && !isset($_SESSION['keyEdu']))
  3.         {
  4.  
  5.             $sqlInsertStatementEdu ="INSERT INTO edu5000 (eduId, eduUsrId, eduName, eduCity, eduState, eduStatus, eduStartDte, eduEndDte, eduDegree, eduMajor, eduMinor, eduExtra, eduLastChgUsr, eduLastChgDte) VALUES (NULL , '".$_SESSION['usrId']."', NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , '".$_SESSION['usrEmail']."', now())";            //PROBLEM! INSERTING MULTIPLE ROWS SOMETIMES, NEXT ADJUST edu fields, NEXT adjust work exp, NEXT references, NEXT non-textbox controls
  6.             $resultEdu0   = mysql_query($sqlInsertStatementEdu); // Insert row into edu
  7.  
  8.             if (!$resultEdu0) {
  9.                 print('Sorry, database error.  Please try again later. If problem persists, contact administrator (reference error 2784)');
  10.             } else {
  11.                 $_SESSION['keyEdu'] = mysql_insert_id(); //sets new edu entry session key to prevent multiple new rows
  12.             }
  13.         }
and the body work...

Expand|Select|Wrap|Line Numbers
  1. <div><a href="resume.php?action=insertEdu&checkId='.$_SESSION['usrId'].'">(+ add education entry)</a></div>unset($_SESSION["keyEdu"]);//END EDUCATION
Jul 1 '09 #1
2 1419
dlite922
1,584 Expert 1GB
I think you need better design because every time the page executes (such as using the Back button) the page executes again (sending the value to DB once more)

If this is suppose to add dynamic fields, I would do it with Ajax.

If this is more resume Edition, I would do this:

With JavaScript I'd insert a set of fields (row) to my table (let's say the Education Section) and when the user is done editing the resume, clicking "Save" would write it to the DB.

Let me know what the use case is, I'm not sure at this point why you're doing what you're doing.




Dan
Jul 1 '09 #3

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

Similar topics

14
by: Reply Via Newsgroup | last post by:
Folks, Say I have a table, ten columns, ten rows - Each with a word in it. I want to change the values of some/all of the cells in the table via a hyperlink. How do I reference each cell and...
5
by: Gunnar Kristiansen | last post by:
Hi! I have a form page which I am using as a frontend for my MySql database (for writing news). I do miss the functionality of a few buttons that could help me insert HTML tags etc, into my main...
14
by: mfrsousa | last post by:
hi there, i have a huge large text file (350.000 lines) that i want to import to a MS Acccess Database, of course i don't want to use Access, but do it with C#. i already have tried the...
1
by: Xah Lee | last post by:
Text Processing with Emacs Lisp Xah Lee, 2007-10-29 This page gives a outline of how to use emacs lisp to do text processing, using a specific real-world problem as example. If you don't know...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.