Red2034 Posted January 31, 2014 Share Posted January 31, 2014 So, I am displaying a masterList table of all my records and using a btn in each row to try to INSERT only that row into another table. Here what I have so far: <?php $classes = $this->db->get('class')->result_array();?> <?php $classesMaster = $this->db->get('class_master')->result_array(); foreach($classesMaster as $row):?> <tr> <td width="50" align="center"> <a href="index.php" onclick="<?php $data['title'] = $row['title']; $data['enroll_date'] = date("Y-m-d"); $this->db->insert('class', $data);?>" > <?php echo get_phrase('enroll');?> </a> </td>... everytime I launch the page it INSERTs all the records from my masterList into the other table... Do you see my mistake? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/285834-all-records-are-inserted-i-only-want-one/ Share on other sites More sharing options...
jcbones Posted January 31, 2014 Share Posted January 31, 2014 PHP is server side. It has no idea about buttons, javascript, forms, etc. All it knows is that you are telling it to insert the data in the foreach loop, which would insert each line as it processes them. What you would have to do, is create a second script, and pass the info to it via a POST. This can be done by a form with hidden values and a submit button, or a submit button that sends it via javascript (AJAX).You would really only need to send the row ID to the second page, as you can do everything inside of the database with an INSERT...SELECT statement. Quote Link to comment https://forums.phpfreaks.com/topic/285834-all-records-are-inserted-i-only-want-one/#findComment-1467247 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.