1

First of all, I am using PHP and MySQL in the Joomla Framework (but not interested at this point in the Joomla MVC structure).

I have a list of data from a database (Table A) and next to that I have added a checkbox. When I click on a checkbox, I want the data from the enabled checkbox to be sent (insert a copy of) to a new table (Table B) when I click on the 'Save' button and have that data listed on a new web page. The ones that are unchecked should not be sent to the new table and therefore should be ignored. Also, the 'Save' button must initially be disabled until a checkbox is checked.

Now, there must be a relationship between the existing data in a table (Table A) to the new table (Table B), so for example when the main existing data is deleted from the table (Table A), it should also automatically delete the data in the new table (Table B).

I know some PHP and MySQL but not enough to figure out some of the above.

Can some smart PHP and MySQL guru please point me to the right direction as I'm pulling my hair out, especially with the checkbox issue. Thanks!

Tony
  • 11
  • 2

1 Answers1

0

To send data to another page and to displaying a message you'll need AJAX. And for that check this page: Ajax passing data to php script

But without the message ( to send data to a page ) , use this ->

Let's say that you have:

<form action="insertInDatabase.php" method="post">
<input type="checkbox" name="cbs[]" value="firstValue">First value<br>
<input type="checkbox" name="cbs[]" value="secondValue">Second value 
</form>

So here you send your data to "insertInDatabase.php". There you have this:

//connection do mySql database

if(!empty($_POST['cbs'])) {

foreach($_POST['cbs'] as $cb) {    

mysql_query("INSERT INTO table2(checkedCheckBoxValue) VALUES('$cb');");


}}
Community
  • 1
  • 1
Vucko
  • 20,555
  • 10
  • 56
  • 107
  • Hi Vucko, thanks for your kind help, it looks promising. Is it possible to help with the 'Save' button relationship as I do not know what to add to the button input. When a checkbox is checked and the 'Save' button is pressed, it should send that field data to Table B with a message saying 'Saved'. Is this possible? Any help would be much appreciated. Thanks! – Tony Nov 03 '12 at 12:33
  • Thanks once again. Another point I may have forgot to mention is that the list of data is automatically listed, I think you call it array, but not sure. I want to take the data from a specific field called 'project_title' when the checkbox is checked. It should then send this data to the database Table B as mentioned before. I really thank you for your time, I think it is making sense to me now. I just need to get all of this to work in my Joomla environment. As Joomla use their own syntax, I'll do it without Joomla for now to get it working. – Tony Nov 03 '12 at 13:16
  • What do you mean with field? Input checkbox value or input text value ? – Vucko Nov 03 '12 at 13:29
  • A field from a table, say a Project Title and next to that Project title field I put the checkbox to save this field into a new table. Basically I'm creating a 'Save as Favourite' project into a different list (new page) that is unique to the user (user id connected to the project title in the table). I'll come to that part later on once I get it working to this point. – Tony Nov 03 '12 at 13:41
  • You can use input type="text" with name="value" value"projectTitle" and disable it so it reamains the same. So then you can easilly send that value to .php page to insert in the mySql table ( via $_POST, catching the name="value" ). – Vucko Nov 03 '12 at 13:55
  • Hi Vucko, thank you for so much of your help so far, but I can't get this to work. I must be doing something wrong. I didn't quite understand your last information as I don't know how to apply it. I'm like a baby and feel like I need to be spoon fed as I am new to PHP and MySQl and I so want to learn. – Tony Nov 04 '12 at 12:34
  • Can you send me to link to your page so I can look at it ? – Vucko Nov 04 '12 at 12:47
  • Ok thanks, let me set it up for you first and then I'll send you the link, maybe I can give you FTP/MySQL access too if that will help. It's only a test page for testing so it won't look pretty. I need to take my dog for a walk first as he is moaning and I haven't taken him out yet. – Tony Nov 04 '12 at 13:10
  • Ok, just post here when you come back and I will answer it. Enjoy the walk ! :D – Vucko Nov 04 '12 at 13:12
  • Hi Vucko, it would probably be better if I send you my email address as I need to send you FTP and maybe MySQL access details. My email address is antonitus@gmail.com. I really appreciate your kind help. My dog always enjoys his walks. – Tony Nov 04 '12 at 14:26